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 |
|
jung1975
Aged Yak Warrior
503 Posts |
Posted - 2005-02-09 : 11:08:08
|
| How can I convert the number with decimal points to percentage?For example,0.2345 --> 20%0.89768 --> 90%0.346578 --> 30% |
|
|
AndyB13
Aged Yak Warrior
583 Posts |
Posted - 2005-02-09 : 11:16:06
|
| SELECT CONVERT(int,ROUND(0.2345 * 100,-1)) --> 20%SELECT CONVERT(int,ROUND(0.89768 * 100,-1)) --> 90%SELECT CONVERT(int,ROUND(0.346578 * 100,-1)) --> 30%Andy |
 |
|
|
jung1975
Aged Yak Warrior
503 Posts |
Posted - 2005-02-09 : 11:56:46
|
| How about something like this?0.2345 --> 0.20.89768 --> 0.90.346578 --> 0.3 |
 |
|
|
AndyB13
Aged Yak Warrior
583 Posts |
Posted - 2005-02-09 : 12:08:47
|
| Look up CONVERT/CAST & ROUND in BOLAndy |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2005-02-10 : 05:49:07
|
| SELECT substring(convert(varchar(10),ROUND(0.2345+0.05,2)),1,3) Madhivanan |
 |
|
|
AndyB13
Aged Yak Warrior
583 Posts |
Posted - 2005-02-10 : 06:06:10
|
madhivananI had already give jung1975 the answer to the original question which is why i pointed him in the direction of BOL when the same question was asked again but with a different output.However your solution doesnt workquote: How about something like this?0.2345 --> 0.20.89768 --> 0.90.346578 --> 0.3
Using your solutionSELECT substring(convert(varchar(10),ROUND(0.2345+0.05,2)),1,3) --0.2 SELECT substring(convert(varchar(10),ROUND(0.89768+0.05,2)),1,3) --0.9SELECT substring(convert(varchar(10),ROUND(0.346578+0.05,2)),1,3) --0.4 (incorrect)Another waySELECT CONVERT(varchar(10),CONVERT(decimal(10,1),ROUND(0.2345,1))) --0.2SELECT CONVERT(varchar(10),CONVERT(decimal(10,1),ROUND(0.89768,1))) --0.9SELECT CONVERT(varchar(10),CONVERT(decimal(10,1),ROUND(0.346578,1))) --0.3Andy |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2005-02-10 : 06:43:06
|
| Thanks for your suggestion AndyMadhivanan |
 |
|
|
|
|
|
|
|