About the arithmetic of BigDecimal data types in Java

Source: Internet
Author: User

Constructor descriptionbigdecimal (int) Creates an object with the integer value specified by the parameter.   bigdecimal (double) creates an object with the double value specified by the parameter.   bigdecimal (long) creates an object with a long integer value specified by the parameter.   bigdecimal (String) creates an object with a numeric value specified by the argument as a string.

BigDecimal (int) Creates an object with the integer value specified by the parameter.

BigDecimal (double) creates an object with the double value specified by the parameter.

BigDecimal (long) creates an object with a long integer value specified by the parameter.

bigdecimal (String) creates an object that has a numeric value specified by the argument as a string

Method description Add (BigDecimal) BigDecimal the value in the object, and then returns the object. Subtract (BigDecimal) subtracts the value from the BigDecimal object and returns the object. Multiply (BigDecimal) multiplies the values in the BigDecimal object and returns the object. Divide (BigDecimal) divides the values in the BigDecimal object, and then returns the object. ToString () willConverts the numeric value of the BigDecimal object into a string. Doublevalue () willThe values in the BigDecimal object are returned as double-precision numbers. bigdecimal object is returned as a single precision number.   bigdecimal object is returned as a long integer.   bigdecimal object is returned as an integer.  

Add (BigDecimal) BigDecimal the value in the object, and then returns the object.

Subtract (BigDecimal) subtracts the value from the BigDecimal object and returns the object.

Multiply (BigDecimal) multiplies the values in the BigDecimal object and returns the object.

Divide (BigDecimal) divides the values in the BigDecimal object, and then returns the object.

ToString () willConverts the numeric value of the BigDecimal object into a string.

Doublevalue () willThe values in the BigDecimal object are returned as double-precision numbers.

Floatvalue () willThe value in the BigDecimal object is returned as a single precision number.

Longvalue () willThe value in the BigDecimal object is returned as a long integer.

intvalue () will bigdecimal object is returned as an integer.  

note that because of general numeric types, such as double , can not accurately represent 16 digits above the number, when using bigdecimal, Application  bigdecimal (String) It makes sense for the constructor to create objects. In addition, bigdecimal is creating objects, we can't use traditional +, -, *, /and other arithmetic operations   characters directly perform mathematical operations on their objects, and must call their corresponding methods. The parameters in the method must also be

About arithmetic for bigdecimal data types in Java

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.