The Bigdecimal.setscale () method is used to format the decimal point
Setscale (1) indicates that a decimal number is reserved and is rounded by default
Setscale (1,bigdecimal.round_down) directly removes the extra decimal digits, such as 2.35 will become 2.3
Setscale (1,BIGDECIMAL.ROUND_UP) Carry processing, 2.35 becomes 2.4
Setscale (1,bigdecimal.round_half_up) rounded, 2.35 turns 2.4setScaler (1,bigdecimal.round_half_down) rounded, 2.35 turns 2.3, and if it's 5, it's down.
notes:1:scale refers to the number of digits after your decimal point. For example, 123.456 score is 3.
Score () is the method in the BigDecimal class.
For example: BigDecimal B = new BigDecimal ("123.456"), B.scale (), return is 3.
2:
Roundingmode is a reserved mode for decimals. They are all constant fields in BigDecimal, and there are many kinds.
For example: Bigdecimal.round_half_up means 4 to 5 in.
3:
Pubilc BigDecimal Divide (BigDecimal divisor, int scale, int roundingmode)
I used a BigDecimal object to divide the result after the divisor, and asked the result to retain a scale decimal place, roundingmode that is what the retention mode is, is rounding ah or other, you can choose!
4: For the general Add, subtract, multiply the decimal place of the method is formatted as follows:
BigDecimal mdata = new BigDecimal ("9.655"). Setscale (2, bigdecimal.round_half_up);
System.out.println ("mdata=" + mdata);
----Results:-----mdata=9.66
A companion tour, a free dating site: www.jieberu.com
Push family, free tickets, scenic spots: www.tuituizu.com
Bigdecimal.setscale processing Java decimal point [go]