如何从SQL Server中的money数据类型转换? [英] How do I convert from a money datatype in SQL server?

查看:782
本文介绍了如何从SQL Server中的money数据类型转换?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在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数据类型转换?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆