SQL Server rounding do you have any other methods besides using round?

Source: Internet
Author: User
Introduction

Today and test communication a percentage calculation method encountered a problem, I used in the stored procedure strong to cast (32.678 as Decimal (5,1)) I think this method will only retain a decimal place, I give the test reply is I did not use the rounding function, the data is not rounded, The test says that the data that they have verified is rounded. Thought of here so I tried again every compute point of the stored procedure, only to discover this problem.

ROUND

We would definitely prefer the round function if the data type of the field is decimal (18,10) When rounding is used and the decimal point is reserved, and a lot of 0 will appear after rounding.

Cast and convert

In fact, I did not intend to use a strong turn round the results, just to get the data that meet my requirements, today only found that the two strong turn will also round the results, that is, the following three statements will return the same result value

Select ROUND (32.678,1)    --32.700select CAST (32.678 as DECIMAL (5,1))  --32.7select convert (NUMERIC (5,1), 32.678 )  --32.7

SQL Server rounding do you have any other methods besides using round?

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.