Round () rounding pit in MySQL

Source: Internet
Author: User
Tags numeric value
When calculating a numeric value, an error is generated by changing a number from code rounding to SQL rounding for integer processing. The field is a varchar type, and the modified result is calculated with the previous result when the decimal bit is. 5 rounding carry, there is an error. For example 2.5, when the field type is a varchar or double type, the round function is used, the result is 2, and decimal is normal. Execute sql: SELECT C_varchar,round (C_varchar), C_double,round (c_double), C_decimal,round (c_decimal) from round_test Run Result: 2.5 2 2.50 2 2.50 3 Refer to the relevant information, see someone said adding a field value a decimal that does not affect the result, the value can be normal, test it, indeed. Execute sql: SELECT C_varchar,round (c_varchar+0.000001), C_double,round (c_double+0.000001), C_decimal,round (C_decimal) from Round_test operation Result:2.5 3 2.50 3 2.50 3 specific reasons, follow-up analysis ...

Round () rounding pit in MySQL

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.