round

# round

• 2012年8月20日 13:49

Hi,
I am rounding numbers to 2 decimal places.
How is it possible to get the 0 at the end also?
For example, rounding 8.1243 gives 8.12
But rounding 6.4 gives 6.4 whereas I would like to see 6.40
OR if the answer is say 2 I would like to see 2.00
Thanks

### 全部回复

• 2012年8月20日 13:52

cast to two decimal places

select cast(ROUND( 6.4,2) as decimal(3,2))

vt

• 2012年8月20日 13:54

Hello arkiboys,

In common it's the part of the client how to display the values; here with pending 0.

But some client you can force to display them by using a fix floating point datatype like decimal:

`SELECT CONVERT(decimal(20, 2), 6.4)`

Olaf Helper
Blog Xing

• 2012年8月20日 13:54

Try

`select cast(6.4 as decimal(10,2))`

• 2012年8月20日 13:55

You've got some solutions, but keep in mind, that this pretends a precision of the value, which is not given due to the rounding.
• 2012年8月20日 13:58

Try

cast(round(2,2) as decimal(18,2))

cast(round(8.1243,2) as decimal(18,2))

Many Thanks & Best Regards, Hua Min

• 2012年8月21日 9:15

Thank you all