Rounding of SQL Server values

Source: Internet
Author: User

Read Catalogue

    • Way 1-round
    • Way 2-cast

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

The personal advice is to use the cast method:

Back to Top Way toround

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

Back to Top mode of thecast

Cast Rounding:

SELECT cast (' 123.456 ' as Decimal (2)) ===>123.46select CAST (0.996123 as Decimal (38,2))  results 1.00SELECT  CAST (' 123.456 ' as Dec (2))   ===>123.46

If you think reading this blog gives you something to gain, you might want to click " recommend " in the lower right corner.

If you want to find my new blog more easily, click on " Follow me "

If you want to give me more encouragement, you may wish to click on the right, " enjoy your stay"

Blog is his own summary of the results of learning, learning to summarize the knowledge-"analysis of the problem-" to solve the problem.

Where the views/descriptions in the text are incorrect, please correct them.

Thank you for your reading, if you are interested in the content of my blog, please continue to follow my following blog, I am yxtic.

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.