如何从SQL Server中的money数据类型转换?

编程入门 行业动态 更新时间:2024-10-28 03:30:12
本文介绍了如何从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数据类型转换?

本文发布于:2023-10-28 02:00:37,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1535170.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:数据类型   SQL   Server   money

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!