The Bigdecimal.setscale () method is used to format the decimal point
Setscale (1) means to keep a decimal number by default by rounding
Setscale (1,bigdecimal.round_down) directly remove the extra decimal places, such as 2.35 will become 2.3
Setscale (1,BIGDECIMAL.ROUND_UP) carry handle, 2.35 becomes 2.4
Setscale (1,bigdecimal.round_half_up) rounded, 2.35 became 2.4 setscaler (1,bigdecimal.round_half_down) rounded, 2.35 turns 2.3, if it's 5, it's down.
Note: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 (), the return is 3.
2:
Roundingmode is a retention pattern for decimals. They are all constant fields in BigDecimal, and there are many kinds.
For example: BIGDECIMAL.ROUND_HALF_UP says is 4 homes 5.
3:
Pubilc BigDecimal Divide (BigDecimal divisor, int scale, int roundingmode)
I use a BigDecimal object divided by the result of divisor, and I want this result to keep a scale decimal place, roundingmode means what the retention mode is, rounded or otherwise, you can choose for yourself.
4: For the general Add, subtract, multiply method of decimal format is as follows: BigDecimal mdata = new BigDecimal ("9.655"). Setscale (2, BIGDECIMAL.ROUND_HALF_UP);
System.out.println ("mdata=" + mdata); ----Results:-----mdata=9.66
Http://hi.baidu.com/hsyl/blog/item/5a690df4b546a6e57709d7a5.html