You need to sign in to do that
Don't have an account?
Ross.ax1563
Rounding to the nearest 50
Hi All
I do I round a decimal value to the nearest 50 (in apex)?
Many thanks
Ross
function readOnly(count){ }
You need to sign in to do that
Don't have an account?
Hi All
I do I round a decimal value to the nearest 50 (in apex)?
Many thanks
Ross
Hi,
Use
Math.round(Number * decPlace) / decPlace;
where decPlace is number of decimal places u want to round.
if that varaible is decimal or double ,, you can make use of rouding mode functoionality check it out this
http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_methods_system_decimal.htm#apex_decimal_rounding_mode
Decimal result = origin - math.mod(origin + 25, 50);
To get the nearest 0.50, You will just need to adjust this slightly differently:
Decimal result = origin - (math.mod((origin+0.25)*100,100)/100);
Note that this method is roughly equivalent to ibtesam's answer, but demonstrates how to round to any arbitrary decimal place or whole integer.