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

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -