Math. Round rounded

Source: Internet
Author: User
Today, the customer ran over and told me that the price calculated in our program was incorrect. I checked and found that the price was converted, and the result was probably a large number of decimal places, only two prices can be printed on the document, So math is called for the price. the round (price, 2) function is rounding.

The unit price is 1.805, And the return value of the function math. Round (1.085, 2) is 1.80. According to the rounding principle, the result should be 1.81.

After some Google attacks, we found Microsoft was right. We were wrong. :(

It turns out that there is also an international practice, called odd-in-even homes. This means that when the first digit in the Round-off position is an odd number, it will go in. If it is an even number, it will go in, this is also the principle of fairness.

However, in international practice, many enterprises in China do not work. To cope with their requirements, we can use math. Round (price, 2, midpointrounding. awayfromzero.

Math. Round rounded

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.