Java Compute Overflow

Source: Internet
Author: User

In Java/js the decimal type is calculated (accumulate and so on), after the calculation of the results of all the chaos seven or eight in the data, do not know what the reason. But the solution is as follows:

1. Solutions in Java, steps:

  A. Convert decimal data into double type:

Double XMZ = 0 D;

BigDecimal zxmz = zx.getmz ();

xmz= zxmz==null?0d:zxmz.doublevalue ();

  B. The converted double data is computed and then formatted by DecimalFormat:

Java.text.DecimalFormat df = new Java.text.DecimalFormat ("#.0000");

Df.format (xmz+ (Zxmz==null?0d:zxmz.doublevalue ()));

  C. Finally, convert the DecimalFormat formatted data into a double type:

Double.valueof (Df.format (xtj+ (Zxtj==null?0d:zxtj.doublevalue ()));

Java.text.DecimalFormat df = new Java.text.DecimalFormat ("#.0000"); BigDecimal zxmz = ZX.GETMZ ();//ZX.GETMZ () This is the data I get from my program Double xmz = 0D;XMZ = Double.valueof (Df.format (xmz+ (zxmz== Null?0d:zxmz.doublevalue ())));

2. The workaround in JS:

Use substring, intercept

Finally, if you can calculate in the SQL statement, you can calculate it directly in SQL, so as to avoid the above problems  

Java Compute Overflow

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.