Double decimal point, double decimal point

Source: Internet
Author: User

Double decimal point, double decimal point

Generally, the compiler parses a literal with a decimal point into a double value.

For example, a literal value is directly put into the code. Because it has a decimal point, the default value is double.

The output result is: 1.12345678912345 (the last number is lost). This is because the precision of the double value is so long. Is there any way to make the output result complete ?? We can declare the literal value to the decimal type, and append an M or m suffix to achieve this. There is another way to prevent the last digit from being discarded, you can use the format string and round-trip format specifier R or r for conversion. Example: string. format ("{0: R}", 1.123456789123477), output result: 1.123456789123477, the last number is still in the round-trip format. If the returned string is converted back to the value, the original value is certainly obtained. If the round-trip format is not used, the input and output values must be different.

Related Article

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.