|
|
Question : How do remove trailing zeros in a decimal number
|
|
Is there a way i can remove trailing zeros from a decimal number; eg. my data looks like this; 1.45600000 2.45140000
and I would like it to look as below; 1.456 2.4514
thks.
|
Answer : How do remove trailing zeros in a decimal number
|
|
That leaves the decimal point at the end of '200'.
Try
SELECT CASE WHEN RIGHT(CONVERT(VARCHAR(20),x),2) = '.0' THEN REVERSE(SUBSTRING(REVERSE(CONVERT(VARCHAR(20),x)),3,20)) ELSE CONVERT(VARCHAR(20),x) END FROM foo
Or, try
SELECT CASE WHEN RIGHT(CONVERT(VARCHAR(20),x),2) = '.0' THEN REVERSE(STUFF(REVERSE(x),1,2,NULL)) ELSE CONVERT(VARCHAR(20),x) END FROM foo
Regards, Bill
|
|
|
|
|