SQL – How to round a float to 2 (or any) decimal places

You can use the str() function to trim a float value to X number of places:

STR ( float_expression [ , length [ , decimal ] ] )

Example for a Total of 7 characters with 2 to the right of the decimal point:
select str(12345.6789, 7, 2)

Result:
12345.68

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s