Don't have an account?
Search for an answer or ask a question of the zone or Customer Support.
You need to sign in to do that
Sign in to start searching questions
Signup for a Developer Edition
Sign in to start a discussion
How come the format method on Decimal always strips trailing zeroes?
For example, if
Decimal d = 1234.00;
d.format() => 1,234
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().
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().