Today, my colleague asked me how to use SQL statements to format double-type data. For example, I only took the two digits after the decimal point, found some relevant information, and recorded it, it will always be useful in the future.
-- Returns the number before the decimal place, excluding rounding.
Select left ('2014. 100', charindex ('.', '2014. 100')-1)
Where: charindex ('. ',' 30000. 72234 ') to get the decimal point.-1 indicates all the digits before the decimal point. If you want to get n after the decimal point, you can write it as + N. It is quite useful.
-- Each three digits are separated by commas (,), leaving two decimal places. Rounding is not considered.
Select convert (varchar, cast (round (30000.72234, 0) as money), 1)
-- Each three digits are separated by commas (,), leaving no decimal places. Rounding is considered.
Select left (convert (varchar, cast (round (30000.72234, 0) as money), 1), charindex ('. ', convert (varchar, cast (round (30000.72234, 0) as money), 1)-1)