I have a column DECIMAL(9,6)
i.e. it supports values like 999,123456.
But when I insert data like 123,4567 it becomes 123,456700
How to remove those zeros?
Advertisement
Answer
A decimal(9,6)
stores 6 digits on the right side of the comma. Whether to display trailing zeroes or not is a formatting decision, usually implemented on the client side.
But since SSMS formats float
without trailing zeros, you can remove trailing zeroes by casting the decimal
to a float
:
select cast(123.4567 as DECIMAL(9,6)) , cast(cast(123.4567 as DECIMAL(9,6)) as float)
prints:
123.456700 123,4567
(My decimal separator is a comma, yet SSMS formats decimal with a dot. Apparently a known issue.)