schavalam
asked on
how to round the double value
if the number is 1.4567 then i need out is 1.46 so what to.
i am using java.lang.Math.round(1.456 7) getting output is 1 but i want 1.46
please help me
i am using java.lang.Math.round(1.456
please help me
Multiply it by 100, round it then divide it by 100.
Hi schavalam:
use java.math.BigDecimal class. It is meant for this purpose only (currency fomatting, which as you know goes to 2 decimal points of precision like $23.75)
Taps
use java.math.BigDecimal class. It is meant for this purpose only (currency fomatting, which as you know goes to 2 decimal points of precision like $23.75)
Taps
>>getting output is 1 but i want 1.46
You must be assigning it to an integral variable such as int or long. Assign to a double or float
You must be assigning it to an integral variable such as int or long. Assign to a double or float
CEHJ: Math.round() returns a long or an int, so can't be used to round a double.
Not like you to miss that :-(
Not like you to miss that :-(
You're right ;-)
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Use the RoundUp/RoundDown option on BigDecimal.