Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

rounding a number

Status
Not open for further replies.

katgirl

Programmer
Jul 6, 2006
114
0
0
US
Just wondering the best way to round a number as part of select statement.

Right now I am getting numbers like 1.05838784 - I would like to round this to 1.06.

Is there a function to do this... or a datatype I can cast to.

Thanks
 
There is a function and it is called – surprise – ROUND()

SELECT ROUND(1.05838784,2)
will give you what you want


Walid Magd (MCP)

The primary challenge of every software development team is to engineer the illusion of simplicity in the face of essential complexity.
-Grady Booch
 
I tried that... I get back 1.060000000 !

Don't want to see all those extra zeroes

:)
 
SELECT STR(ROUND(1.05838784,2),10,2)

Adjust 10 or calculate it using the length of the integral part. Read the help for more info. Good luck

Walid Magd (MCP)

The primary challenge of every software development team is to engineer the illusion of simplicity in the face of essential complexity.
-Grady Booch
 
You could also convert to decimal:

Select Convert(Decimal(18,2), 1.05838784)



-George

Strong and bitter words indicate a weak cause. - Fortune cookie wisdom
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top