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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to trim from the right of floating point in sql

Status
Not open for further replies.
Mar 29, 2004
120
US
Hi,

Say I have numeric like: 765.9876000

I want to be able to present it as 765.98, basically leave only 2 numbers to the right of the decimal point?

Round () function does not really work here, I think SUBSTRING () could, but not sure how?

Thanks in advance.
 
Round(765.9876000,2) will return 795.99

If you simply want to throw away the 76000 to leave 765.98
then

multiply by 100 - gives 76598.76
convert the answer to integer - gives 76598
divide by 100 - gives 765.98

use CAST or CONVERT for the middle step
 
As an alternative, using implied conversion to string:

Code:
declare @number decimal(10,4)
set @number = 765.9876000
set @number = parsename(@number, 2) + '.' + left(parsename(@number, 1), 2)
print @number

NB: This wont work if the datatype is money[/]

Hope this helps.

[vampire][bat]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top