Format a number in MS SQL

Hi, I need to format this number

0.23999999999999999

To this

0.240

Any ideas ?
gusdogsAsked:
Who is Participating?
 
Atlanta_MikeCommented:
Or, SELECT CONVERT(DECIMAL(4,3),0.23999999999999999)
0
 
Patrick MatthewsCommented:
Hi gusdogs,

Do you mean make the number display that way in a query result set, or make the number behave in calculations
as if it were 0.240?  (Potentially two very different things...)

Regards,

Patrick
0
 
Atlanta_MikeCommented:
On way... SELECT CONVERT(DECIMAL(4,3),ROUND(0.23999999999999999,2))
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
gusdogsAuthor Commented:
I need to format a calculated number, just for displaying.

Thanks mike, but I may have mislead you

The number could be any number eg 582.566666666 or 0.1299999 whatever,
but I need to display it with 3 decimal places, rounded off to the 3rd decimal place.

0
 
juandsCommented:
Then, following Atlanta_Mike example:
select cast('the number' as decimal(9,3))

Hope this could help.
Regards,

Leandro Nuñez.
0
 
juandsCommented:
my example:

declare @number real;
declare @number2 decimal (9,3);

set @number = '500.259999';
set @number2 = cast(@number as decimal(9,3));

select @number
select @number2


Regards,

Leandro Nuñez.
0
 
gusdogsAuthor Commented:
Thanks mike, that worked, I was being a dumbass.
Thanks to you also Leandro.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.