SQL 舍入并显示到 2 个小数位?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/28408400/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Round And Show To 2 Decimal Places?
提问by Rejwanul Reja
I have a small question to ask. How to round a numeric field upto 2 decimal places, and also show it with 2 decimal places only
我有一个小问题要问。如何将数字字段舍入到 2 个小数位,并仅显示 2 个小数位
For example the following would return 255.88000000000
例如,以下将返回 255.88000000000
select round(255.87908765444,2)
How to get 255.88 only?
如何仅获得 255.88?
Pleas help.
请帮忙。
Thanks,
谢谢,
回答by t-clausen.dk
回答by meskobalazs
If you need it as a string, this should work:
如果你需要它作为一个字符串,这应该工作:
select format(round(255.87908765444,2), 'N2');
回答by Dudi Konfino
use string function substring & char index
使用字符串函数子字符串和字符索引
select SUBSTRING(convert(varchar(20),round(255.87908765444,2)),
1,
CHARINDEX('.',convert(varchar(20),255.87908765444))+2)
回答by Rejwanul Reja
Yes We can use the above solution is..
是的我们可以使用上面的解决方案是..
ROUND(CAST(psd.Price AS DECIMAL(20,4)), 2)
回答by Hitesh
select round(convert(decimal(18,2),255.87908765444),2)