15,562,222 members
See more:
is Fun can Do this :
VB
```20 -> 20

20.00 -> 20

20.5 -> 20.5

20.5000 -> 20.5

20.125 -> 20.125

20.12500 -> 20.125

0.000 -> 0```

in sql??
Posted
Updated 6-Oct-22 20:52pm
phil.o 9-Jan-14 4:55am
Not clear : the database engine will return the values as raw decimals/reals/etc...
What you want to do concerns the presentation of the data, thus should not be managed from the database system, but rather from the presentation layer.

## Solution 1

try this,
SQL
```SELECT convert(DOUBLE PRECISION, 20.00)
SELECT convert(DOUBLE PRECISION, 20.50)
SELECT convert(DOUBLE PRECISION, 20.125)
SELECT convert(DOUBLE PRECISION, 20.12500)```

Happy Coding!
:)

Maciej Los 9-Jan-14 4:57am
Welcome back, Aarti ;) Happy New Year!
+5!
Aarti Meswania 9-Jan-14 4:59am
hi, Maciej Los
Happy new year!
thanks for upvoting :)

## Solution 2

Try this also,

SQL
```select cast(CAST(12.5800 as decimal(18,5)) as float)
select cast(CAST(12.5 as decimal(18,5)) as float)
select cast(CAST(12.58 as decimal(18,5)) as float)
select cast(CAST(0.00 as decimal(18,5)) as float)```

and the out put will be
SQL
```12.58
12.5
12.58
0```

respectively

thanks
animesh

## Solution 3

Realistically, this is a job for your presentation layer. The values from SQL should be correct. Your presentation layer should care about how they are displayed.

## Solution 4

SELECT CAST (SUM(Amount) as decimal(10,2))

CHill60 7-Oct-22 5:19am
Reasons for my downvote: if you take some of the specific examples the OP used your attempt returns the wrong values. E.g. Instead of `20.12500 -> 20.125` your version gives `20.12500 -> 20.13`.
Instead of `20.5000 -> 20.5` yours gives `20.5000 -> 20.50`