Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Adding decimal point

Author  Topic 

rwlopez
Yak Posting Veteran

80 Posts

Posted - 2006-11-21 : 15:56:19
What is the easiest way to add a decimal point to data that does not have one? For example

10000

Should be

100.00

snSQL
Master Smack Fu Yak Hacker

1837 Posts

Posted - 2006-11-21 : 16:23:49
select cast(10000 / 100.00 as decimal(9,2))
gives 100.00
select cast(10056 / 100.00 as decimal(9,2))
gives 100.56
Go to Top of Page

rwlopez
Yak Posting Veteran

80 Posts

Posted - 2006-11-21 : 16:31:04
Thanks
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2006-11-22 : 02:59:59
select round(10000 / 100.0, 2)


Peter Larsson
Helsingborg, Sweden
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2006-11-22 : 03:07:03
quote:
Originally posted by Peso

select round(10000 / 100.0, 2)


Peter Larsson
Helsingborg, Sweden



the round() is a not really required as you are dividing by 100.0


KH

Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2006-11-22 : 03:14:50
If you want to keep maximum decimals digits to two, yes.


Peter Larsson
Helsingborg, Sweden
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2006-11-22 : 03:24:07
unless you are dividing by value other than 100.0


KH

Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2006-11-22 : 03:46:47
If you want no decimals, round(10000 / 100.0, 0). Bu this is the almost the same as integer division. The difference is that ROUND rounds the result to nearest integer whereas integer division clips the fraction part.


Peter Larsson
Helsingborg, Sweden
Go to Top of Page
   

- Advertisement -