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 - Plugin org.apache.maven.plugins:maven-install-plugin:2.4 or one of its dependencies could not be resolved -

Round ImageView Android -

How can I utilize Yahoo Weather API in android -