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 |
|
kdoan
Starting Member
2 Posts |
Posted - 2006-05-19 : 14:17:08
|
| Hi,How do I convert these numbers:1248 to 1250 (3 significant figure) 1243 to 1240 (3 significant figure) 136.6 to 137 (3 significant figure)12.46 to 14.5 (3 significant figure)Thanks in advance!Khanh |
|
|
Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)
7020 Posts |
Posted - 2006-05-19 : 14:25:58
|
| [code]select a = round(1248, -1), b = round(1243, -1), c = round(136.6, 0), d = round(12.46, 1)Results:a b c d ----------- ----------- ------ ------ 1250 1240 137.0 12.50(1 row(s) affected)[/code]CODO ERGO SUM |
 |
|
|
kdoan
Starting Member
2 Posts |
Posted - 2006-05-19 : 14:50:34
|
| Thanks Michael for your quick respond. However in the case that the number is already have 3 significant figures or less than I don't want it to round up or down. How do I prevent that?126 === 126 not 130123 === 123 not 1200.26 === 0.26 not 0.30Khanh |
 |
|
|
Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)
7020 Posts |
Posted - 2006-05-19 : 16:52:48
|
You can set the way you round off a number by setting the length.declare @len intset @len = 0select a = round(123,@len)set @len = 2select b = round(0.26,@len)Results:a ----------- 123(1 row(s) affected)b ---- .26(1 row(s) affected) CODO ERGO SUM |
 |
|
|
|
|
|