Reputation: 451
i have weight column in a table where weight must be inserted with following format '09.230'. Weight column is of varchar type. so value from front end comes as '9.23' it should get converted to above mentioned format i.e.(09.230). I am able to add trailing zero but adding leading zero is a problem. This is what i have done to add trailing zero
CAST(ROUND(@Weight,3,0) AS DECIMAL (9,3))
Suppose @Weight = 6.56 output with above comes out be '6.560' but output wanted as '06.560'.
Upvotes: 2
Views: 6517
Reputation: 172270
RIGHT('0'+ CONVERT(VARCHAR, CAST(ROUND(@Weight,3,0) AS DECIMAL (9,3))), 6)
This
0
in front of it, and012.560
-> 12.560
, but 06.560
-> 06.560
).Do note, though, that this only works for numbers with at most two digits before the decimal point: 100.123
would be truncated to 00.123
!
Upvotes: 3