Once in a social network was asked how to remove trailing zeros in decimal numbers. This was associated with the preparation of a report, which sums concatenate with the text. In the conditions of the problem was stated limit to two decimal places.
Here's an example of data and the desired result:
given
to obtain
0.00
0
10.00
10
2.50
2.5
100.00
100
11.33
11.33
Solutions have been proposed, based on analysis of the line. I also chose the wrong way and proposed the following solution:
Console
Execute
SELECT num,
CASEWHENCAST(num AS INT) = num
THENCAST(CAST(num AS INT)AS VARCHAR)
WHENCAST(num*10AS INT) = num*10
THENLEFT(CAST(num AS VARCHAR), LEN(CAST(num AS VARCHAR)) - 1)
I do not know how much it would still be continued, if one member did not notice that all problems are solved by conversion to the data type
Òèï äàííûõ ñ ïëàâàþùåé òî÷êîé.
float. Really: