Float Type accuracy in Java

Source: Internet
Author: User

 

Today, I found a small problem. I did not talk much about it on the Internet. Here I recorded it to help me solve my own problems.

CodeFragment

1 Float Unit = Double. valueof (actionutils. getbillingtransformunit (request); // The output unit is 1000.0.
2 Float   SVT = (Curvesegment. getendval () + 1 )) / Unit; // Add 0.001
3 Segmentform. setstartvaltemp (string. valueof (SVT ));

 

The minimum unit for calculation is PCT, And the startvaltemp on the page is Meta, so it must be three decimal places when curvesegment. when getendval () is used to retrieve an integer within 10 million, the value of "add one" is displayed on the page. When the value is 20 million, String. valueof (SVT) is changed to 2 decimal places, thus the added 1 is lost.

 

Reference my original introduction on mantis"ProgramThe float unit of the numeric type used is 20000 filled in 20000000, converted to 20000001, followed by a value equal to 1000.0 divided by 20000.0. When the value is in the localized string, the precision loss problem occurs (precision problem, float precision is 7-8 bits, in the case of 8 digits, the first digit is 1. When the second digit is used, is the precision behind the second digit lost ?)"

The problem is that the type accuracy is not satisfied, and it is a type selection problem. Solve the problem using the double type

 

1 Double Unit = Double. valueof (actionutils. getbillingtransformunit (request ));
2 Double SVT = (Curvesegment. getendval () + 1 )) / Unit;
3 Segmentform. setstartvaltemp (string. valueof (SVT ));

 

 

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.