bigdecimal - How can I obtain the first 2 decimal places of a number without considering the weight of successive decimal places in Java? -


in java have number object can have decimal digits.

for instance like: 123.456789

where 123 integer part of number , 456789 decimal part.

ok. how can obtain same number first 2 decimal places without considering weight of successive decimal places.

for example if want number first 2 decimal places want obtain 123.45 , not 123.46 (aproximated because following decimal place >5).

i need if have integer number 3 want obtain 2 first decimal places, 3.00

how can it?

try setscale method below

bigdecimal value = new bigdecimal("123.456789"); bigdecimal bg2 = value.setscale(2, roundingmode.down); system.out.println(bg2);  output: 123.45  input 3, output 3.00 

Comments

Popular posts from this blog

java - Unable to make sub reports with Jasper -

Save and close a word document by giving a name in R -

scala - play framework: Modules were resolved with conflicting cross-version suffixes -