Go Two ways that SQL Server retains several decimals

Source: Internet
Author: User

Original address: http://blog.csdn.net/skyandcode/article/details/23523815

Problem:

The float Momey type in the database will be accurate to many decimal places. But sometimes we don't need to be that precise, for example, to only be accurate to two significant digits.

Solve:

1. Use the Round () function, such as the Round (@num, 2) parameter 2, to retain a two-bit valid number.

2. A better approach is to use CONVERT (decimal (18,2), @num) to implement the conversion, and decimal (18,2) specifies a valid number to retain.

There is a difference between the two methods: using the Round () function, if the @num is a constant, such as Round (2.3344,2), it changes to 0 after the valid number, to 2.3300. But the Convert () function does not.

Go Two ways that SQL Server retains several decimals

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.