Rounding of SQL Server values

Source: Internet
Author: User

Rounding in SQL usually has two ways: round and cast (... as decimal ()).

The personal advice is to use the cast method:

Mode 1:

After testing, the same can be rounded, but round the following example 1 will be an error,

Example 1:select round (0.996123,2) Error: arithmetic overflow errors when converting expression to data type numeric.

Example 2:select round (0.99432,2) results are 0.99000

Mode 2:

Cast Rounding:

SELECT CAST('123.456'  as decimal( -,2))===>123.46SELECT CAST(0.996123  as DECIMAL( -,2)) results are1.00SELECT  CAST('123.456'  as Dec( -,2))===>123.46

Rounding of SQL Server values

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.