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

Truncating a decimal 1

Status
Not open for further replies.

ross1228

Programmer
Oct 20, 2006
14
US
In ms sql
I have 1.1234567
I want to return 1.12

I tried ROUND(1.1234567, 2) but that gives me 1.230000
I also tried TRUNC and TRUNCATE.
 
how about

declare number decimal
set number = 1.1234567


REPLACE( number , Right( number, 5 ), '' )
 
or better yet if the numbers vary and decimal doesnt work as a decimal ;|

declare @number float
set @number = 1.1234567

select left( @number, 4 )
 
Converting a number to a decimal also performs rounding, so I would suggest this....

Code:
Select Convert(Decimal(10,2), 1.1234567)

The decimal data type allows for precision and scale. The precision (in this example = 10) means.... allow 10 total digits. Scale (in this example = 2) means... allow 2 digits after the decimal.

So, Decimal(5,2) has a range of -999.99 to 999.99

Make sense?

-George

"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
 
PERFECT!

Select Convert(Decimal(10,2), 1.1234567)

That is exactly what I needed. Thanks gmmastros!

Thanks for all the suggestions.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top