You need to sign in to do that
Don't have an account?
Marco Santos
How to round a number?
Hi,
Could somebody help me round a number in my apex code?. Namely I have a number for example:
53732.99999999, then I would round this number to 53,733.00
Currently I am using the following code:
Thank in advance
Could somebody help me round a number in my apex code?. Namely I have a number for example:
53732.99999999, then I would round this number to 53,733.00
Currently I am using the following code:
roundNumber.setScale(2,System.Roundingmode.DOWN).format(),although is not formating the number correctly as I am receiving 53,732.99. Any help will be appreciated
Thank in advance
Use setScale(0) simply
For example:
All Answers
Try this code:-
Decimal d = 53732.99999999;
Decimal i=Math.Round(d);
system.debug('Result::::::::::'+i);
Hope it works
Thanks
Anil.B
53733.00 rather than 53733 (currently this is how your example work)?
Thanks again
If you're attempting to display the decimal in Visualforce, you could use the apex:outputText to format the decimal with the way you desire. For example:
The following will take the yourDecimalVariable member variable in your Apex controller and format it with trailing zeros.Here is the updated code for rounding a number to TWO decimal places in apex. Best Regards,
Mithun.
Use setScale(0) simply
For example: