Note the small point after the project is published in Java, and the handling of the amount in Java

Source: Internet
Author: User

After the project is published, sometimes some minor changes are made, especially for some constants, such as the definition of some special accounts, third-party key values, when modified, I have been lazy before, because the project on the server, access speed is also limited, the replacement of the whole project is very troublesome, So it's just a substitute for a different class. This can lead to a very serious problem is that after the modification has no effect, because for public final static int .... Similar to this constant at compile time, the other class's bytecode has been written in the constant, rather than the constant reference, so just simply replace a class, compile this class is not right, and to all the classes are compiled once and replace, so can not be lazy AH!!!

In the Java project, will certainly encounter for the amount of processing, so for the amount of processing, the average person, think about it, with a float, double, not on its rounding and so on, this is not right, for the amount, we can use, but also the best use is BigDecimal, This class solves the problem of various data processing in Java, which corresponds to the decimal field in the database, so in future projects, the amount must be paid attention to.

BigDecimal number = Num.setscale (2,roundingmode.half_even);

Setscale is the method of setting the precision, and Roundingmode.half_even is called Banker rounding method, for the calculation of the amount above the use of such operations can reduce the algorithm above the amount above the loss, improve the project accuracy.

Note the small point after the project is published in Java, and the handling of the amount 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.