Rounding a BigDecimal in Java doesn't return the expected number -


i have property called m_fobst contains following number: 1.5776. here i'm trying round it:

   this.m_fobst.setscale(2, bigdecimal.round_half_even) 

however, number 1.60 when should getting 1.58.

can explain why?

bigdecimal immutable - make sure using value returned setscale() method.

bigdecimal bd = new bigdecimal("1.5776");  bd = bd.setscale(2, bigdecimal.round_half_even); 

in case, bd 1.58


Comments

Popular posts from this blog

matlab - How to equate a structure array to structure array -

c# - Operator '==' incompatible with operand types 'Guid' and 'Guid' using DynamicExpression.ParseLambda<T, bool> -