1. Construct a BigDecimal object:
1 // Create a BigDecimal object, initialization must use a string, because numeric initialization results in approximate values, inaccurate 2 New BigDecimal ("1.232324"); 3 4 // to replace floating-point numbers with BigDecimal objects 5 double d = 1.3422424; 6 BigDecimal bigdecimaltwo =bigdecimal.valueof (d);
View Code
2. BigDecimal member Method:
1 //bigdecimalone plus bigdecimaltwo, then return a new object2 Bigdecimalone.add (bigdecimaltwo);3 4 //Bigdecimalone minus Bigdecimaltwo, then returns a new object5 bigdecimalone.subtract (bigdecimaltwo);6 7 //bigdecimalone times Bigdecimaltwo, then returns a new object8 bigdecimalone.multiply (bigdecimaltwo);9 Ten //Bigdecimalone divided by Bigdecimaltwo and then returns a new object OneBigdecimalone.divide (Bigdecimaltwo);
View Code
3. BigDecimal objects into basic data types:
// converts the value of the BigDecimal object to the corresponding string bigdecimalone.tostring (); // BigDecimal to return a double value Bigdecimalone.doublevalue (); // BigDecimal to return float Bigdecimalone.floatvalue (); // BigDecimal to return a Long value Bigdecimalone.longvalue (); // BigDecimal returns an int value Bigdecimalone.intvalue ();
View Code
4, the way of rounding in Java:
Java decimal Processing, BigDecimal class application