I have column decimal(10,5)
— VALUE , and column int
— PICTURE .
So, I need to round VALUE to PICTURE digits after decimal point.
For example:
VALUE = 10.50000
and PICTURE = 2
, I want to get 10.50
;VALUE = 0.15371
and PICTURE = 3
, I want to get 0.154
If I use just Round()
or Cast(Round(...) as nvarchar)
, then I have trailing zeros. If I Cast()
to float
, then I loose zeros.
Is there any solution?
You can use the str()
function with trim()
:
select trim(str(value, 20, picture))
str()
converts a number to a string with the specified length and precision. Sadly, it produces a fixed length string, left padded with spaces. The trim()
removes the spaces.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.