username
20th May 2015, 10:08
Hi,
Need help on rounding issue. I got problem with round function. I want to round up the 4 decimal amount to 2. For example:
108,735.2166 should be 108,735.22
108,735.2145 should be 108,735.21
But I could not get the correct amount.
I try the function round(r.amount,2,2). But I did not get the correct amount.
Thanks in advance.
bhushanchanda
20th May 2015, 10:49
Hi,
Just tried this piece of code and it works just fine -
double x1,x2
x1 = 108735.2166
x2 = round(x1,2,2)
Juergen
20th May 2015, 12:28
Hi,
I think here the normal round mode should be used, so round(amount,2,1)
bdittmar
20th May 2015, 18:12
Hi,
Need help on rounding issue. I got problem with round function. I want to round up the 4 decimal amount to 2. For example:
108,735.2166 should be 108,735.22
108,735.2145 should be 108,735.21
But I could not get the correct amount.
I try the function round(r.amount,2,2). But I did not get the correct amount.
Thanks in advance.
Hello,
from DEV-Guide:
round()
Syntax:
function double round (double value, long diga, long mode)
Description
This rounds a given value to a specified number of decimal places.
Arguments
double value The value to be rounded.
long diga The number of decimal places to which value is to be rounded.
long mode 0 truncate (for example, both 1.5 and 1.49 are rounded down to 1)
1 normal round (for example, 1.5 is rounded up to 2; 1.49 is rounded
down to 1)
2 round up (for example, both 1.5 and 1.49 are rounded up to 2)
Return values
The rounded value. Or the original value ( value ) if an error occurs.
Because the return value is of type double, the number of digits after the decimal sign is always 6. For example, round(1.345, 2, 1) returns 1.350000.
Regards