function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
laxlax 

Problem using setscale

Hi,

 

I want to display a value as 123,456.99. So I write as decimal.setscale(2).format()

This is working fine for values having two digits for decimal. But say if I have an integer it displays 123,456 instead of 123,456.00. Or if a value is 123,456.90 it displays 123,456.9.

 

Am I missing something? Thanks.

SteveBowerSteveBower
What do you get if you use toPlainString()? 
werewolfwerewolf
Yeah, I don't think setScale does what you think it does.  It will round the decimal to the precision you set in setScale, but it won't guarantee that the string representation will show that many digits as far as I know.
laxlax
Thanks, toPlainString is keeping the .00 but it removed comma. What is the best way to do this? putting if condition to the string that if .00 is found then no need to append, else append .00?
SteveBowerSteveBower

No, I don't think you're missing anything.  Hacking the string yourself may be your final solution.

 

If the Decimal is associated with a Currency field salesforce will correctly format it as currency.  Is there some way your display can do that?  e.g. are you writing visualforce code?

 

Best, Steve.

 

laxlax

Hello Steve,

 

What I am trying to achieve(in a VF page) is to add two currency values in a decimal variable. Then display the decimal variable. Or simply just take one currency value and display it via decimal variable(wanting 123,456,678.XX format, XX can be 00 as well)

Message Edited by lax on 04-15-2009 03:43 AM