It is 2023 and point mentioned by luckyme is still valid. There are scenarios when we would like to print the decimals on a PDF even if it is .00. We can always remove them if needed. Also, showing trailing zeros on PDF matches when users see on the UI.
I believe the format() function tries to produce a tidy representation of the double. I mean, you wouldn't expect it to return 1234.0000, right?
It would be nice to have the Apex equivelent of DecimalFormat(d) though.
Cheers,
I expect it to respect the scale of the decimal which is what toPlainString() does.
Decimal d = 1234567.00;
d.toPlainString() => '1234567.00'
d.format() => '1,234,567' now
but I think it should be '1,234,567.00'
If I want strip the trailing zeroes, I can always do
d.stripTrailingZeros().format().