Java FAQ Series

Source: Internet
Author: User

Puzzle One: Small problems with data operations

1) to avoid using float and double type when the problem requires an exact answer, use the int long bigdecimal type. This is because not all decimals can be represented as exact representations of binary floating-point numbers when operating in Java virtual. Therefore, when doing business calculations (similar to bank calculations) it is recommended to use BigDecimal of course when constructing a double type with a string instead.

2) often divisible. For the process of multiplying multiple numbers: long x =24*60*60*1000*1000 causes an overflow of type int during this operation, because Java does not have an attribute of the target type, so the number of two int is multiplied by the int type. So at the end of the time will be turned to long but in the process of the operation is already overflow so the result will be inaccurate. Workaround the first operand is a destination type.

Java FAQ Series

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.