SQL Server numeric rounding, two digits after decimal point

Source: Internet
Author: User

1. The round () function is used in rounding. The first parameter is the data to be operated, and the second parameter is used to display the number of decimal places after rounding.

2.The numeric function has two parameters. The first parameter indicates the data length, and the second parameter indicates the number of digits after the decimal point.

For example:

Select cast (round (12.5, 2) as numeric ))Result: 12.50

Select cast (round (12.555, 2) as numeric ))Result: 12.56

Select cast (round (122.5255, 2) as numeric ))Result: 122.53

Select cast (round (1222.5255, 2) as numeric ))Result: an error is returned! The reason is:1222.5255, the integer is 4, the decimal place is 2, and the sum is 4 + 2 = 6, which exceeds the five digits set by Numeric,You can increase or decrease numeric parameters, such as numeric ).

This article is reproduced after a adjustment, reproduced from: http://blog.csdn.net/caoyuanlang_11/article/details/5410833

1. The round () function is used in rounding. The first parameter is the data to be operated, and the second parameter is used to display the number of decimal places after rounding.

2.The numeric function has two parameters. The first parameter indicates the data length, and the second parameter indicates the number of digits after the decimal point.

For example:

Select cast (round (12.5, 2) as numeric ))Result: 12.50

Select cast (round (12.555, 2) as numeric ))Result: 12.56

Select cast (round (122.5255, 2) as numeric ))Result: 122.53

Select cast (round (1222.5255, 2) as numeric ))Result: an error is returned! The reason is:1222.5255, the integer is 4, the decimal place is 2, and the sum is 4 + 2 = 6, which exceeds the five digits set by Numeric,You can increase or decrease numeric parameters, such as numeric ).

this article after the system is reproduced, make an adjustment, reprinted from: http://blog.csdn.net/caoyuanlang_11/article/details/5410833 >

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.