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.
| 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 example10000Should be100.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.00select cast(10056 / 100.00 as decimal(9,2))gives 100.56 |
 |
|
|
rwlopez
Yak Posting Veteran
80 Posts |
Posted - 2006-11-21 : 16:31:04
|
| Thanks |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2006-11-22 : 02:59:59
|
| select round(10000 / 100.0, 2)Peter LarssonHelsingborg, Sweden |
 |
|
|
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 LarssonHelsingborg, Sweden
the round() is a not really required as you are dividing by 100.0 KH |
 |
|
|
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 LarssonHelsingborg, Sweden |
 |
|
|
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 |
 |
|
|
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 LarssonHelsingborg, Sweden |
 |
|
|
|
|
|
|
|