rounding extra zeros

vbnetcoder
vbnetcoder used Ask the Experts™
on
When i round a number in T-SQL i get extra zeros

For example this:


SELECT Round(1.7656543543543, 2)

Returns this

1.7700000000000

How would i return just this 1.77
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Senior Software Developer
Commented:
SELECT CAST(ROUND(1.7656543543543, 2) AS FLOAT)
Chris LuttrellSenior Database Architect

Commented:
Round just rounds and does not change the type of the variable.  In your case the static number 1.7656543543543 is considered NUMERIC(14,13) by SQL and thus your select returns all 13 decimals. Casting as FLOAT works of if you always need 2 decimal places then use NUMERIC(8,2) or something similar.

Author

Commented:
ty

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial