How to make a double type in Java not represented by scientific notation

Source: Internet
Author: User

In Java, when a double or bigdecimal decimal is converted to a string, it is often expressed in scientific notation, and we generally do not want to use scientific notation, which can be done by:
DecimalFormat a = new DecimalFormat ( "#,# #0.00000000");
        system.out.println (A.format (11111111.0000001000000001)); The
way to format the output string.

for BigDecimal decimals, the ToString function can be used with confidence if the precision <=6 is established. However, for >6 precision, it is possible to use scientific notation, the viewer code is judged as follows:
Long adjusted =-(long) scale + (coeff.length-1);
        if ((scale >= 0) && (adjusted >=-6)) {
  & nbsp;                the ToString of non-scientific counting method .
        }
where scale refers to the precision of BigDecimal,
Coeff corresponds to the ToString string that uses BigInteger stored values, Coeff = Intval.abs (). ToString (). ToCharArray (), That is, BigDecimal the integer value under the corresponding precision, such as BigDecimal OB = new BigDecimal (0.00000011), the accuracy of OB is 7, then coeff= "1"; if Ob=new BigDecimal ( 0.10000011), then coeff= "1000001", if Ob=new BigDecimal (0.00000001), then coeff= "0";

Use more BigDecimal less double

How to make a double type in Java not represented by scientific notation

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.