我在SQL Server中具有money数据类型。如何在查询中将0.00重新格式化为0?
I have a money data type in SQL Server. How do I reformat 0.00 to 0 in my query?
推荐答案正常的货币转换将保留单个便士:
Normal money conversions will preserve individual pennies:
SELECT convert(varchar(30), moneyfield, 1)最后一个参数决定输出格式是什么:
The last parameter decides what the output format looks like:
0(默认值)小数点左边每三位数不带逗号点和小数点右边的两位数字;例如4235.98。
0 (default) No commas every three digits to the left of the decimal point, and two digits to the right of the decimal point; for example, 4235.98.
小数点左边每三位逗号,小数点右边每两位数字;例如3,510.92。
1 Commas every three digits to the left of the decimal point, and two digits to the right of the decimal point; for example, 3,510.92.
2小数点后三位和小数点后四位都没有逗号;例如4235.9819。
2 No commas every three digits to the left of the decimal point, and four digits to the right of the decimal point; for example, 4235.9819.
如果要截去几美分并以磅为单位,则可以四舍五入到最接近的磅,最低到最低的整磅,或最高到四舍五入。英镑:
If you want to truncate the pennies, and count in pounds, you can use rounding to the nearest pound, floor to the lowest whole pound, or ceiling to round up the pounds:
SELECT convert(int, round(moneyfield, 0)) SELECT convert(int, floor(moneyfield)) SELECT convert(int, ceiling(moneyfield))更多推荐
如何从SQL Server中的money数据类型转换?
发布评论