This week's book giveaway is in the Agile and other Processes forum. We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line! See this thread for details.
I have a BigDecimal Value, with the value 23.2999999764 i want to round this value to 2 digits after the decimal point so the value is 23.30 but i want to keep the value in my BigDecimal , is this possible, and if, how ?
Frank
Andrew Caldwell
Greenhorn
Joined: Aug 18, 2008
Posts: 1
posted
0
They're immutable so if you call .scale on it, you'll return a new BigDecimal that's the same but to two decimal places.
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32651
4
posted
0
Welcome to the Ranch, Andrew Caldwell
Frank Jacobsen, please read this thread which discusses a similar problem. You have probably instantiated your BigDecimal from a double, which immortalises and maintains the imprecision of floating-point arithmetic. You would be better to use a String to instantiate the BigDecimal.
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32651
4
posted
0
And as Andrew has told you a BigDecimal is immutable so the original reference will still maintain the .2999999999999999 bit.