Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Format a number in MS SQL

Posted on 2006-05-30
7
Medium Priority
?
30,072 Views
Last Modified: 2012-06-21
Hi, I need to format this number

0.23999999999999999

To this

0.240

Any ideas ?
0
Comment
Question by:gusdogs
  • 2
  • 2
  • 2
  • +1
7 Comments
 
LVL 93

Expert Comment

by:Patrick Matthews
ID: 16789785
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
 
LVL 13

Expert Comment

by:Atlanta_Mike
ID: 16789817
On way... SELECT CONVERT(DECIMAL(4,3),ROUND(0.23999999999999999,2))
0
 
LVL 13

Accepted Solution

by:
Atlanta_Mike earned 2000 total points
ID: 16789829
Or, SELECT CONVERT(DECIMAL(4,3),0.23999999999999999)
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:gusdogs
ID: 16789956
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
 
LVL 1

Expert Comment

by:juands
ID: 16791811
Then, following Atlanta_Mike example:
select cast('the number' as decimal(9,3))

Hope this could help.
Regards,

Leandro Nuñez.
0
 
LVL 1

Expert Comment

by:juands
ID: 16791828
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
 

Author Comment

by:gusdogs
ID: 16795958
Thanks mike, that worked, I was being a dumbass.
Thanks to you also Leandro.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

MSSQL DB-maintenance also needs implementation of multiple activities. However, unprecedented errors can hamper the database management. In that case, deploying Stellar SQL Database Toolkit ensures fast and accurate database and backup repair as wel…
Microsoft Jet database engine errors can crop up out of nowhere to disrupt the working of the Exchange server. Decoding why a particular error occurs goes a long way in determining the right solution for it.
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
The Relationships Diagram is a good way to get an overall view of what a database is keeping track of. It is also where relationships are defined. A relationship specifies how two tables connect to each other. As you build tables in Microsoft Ac…
Suggested Courses

569 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question