According to SF documentation Decimal.format() method "Returns the String value of this Decimal using the locale of the context user.", but it leaves only 3 digits after decimal point. It doesn't even matter if you use setScale() method before calling format(). Example from SF documentation:
// U.S. locale
Decimal myDecimal = 12345.6789;
system.assertEquals('12,345.679', myDecimal.format());
As you can see it leaves only 3 digits after decimal point.
Is there a "standard" way to format number in Apex (not Visualforce) using the locale of the context user and leave all the digits after decimal point? Or it should be custom code/logic to handle this?
Best Answer
I've logged an Idea for this issue to ask Salesforce for solving this.
Please also find the following 'work-a-round' code that I've written for my current project to make this failure work either way.
Hope this can help you and please upvote the Idea :)