问题描述
我想问问是否有人知道查询将0值舍去为十进制.
例如:字段名称百分比具有这些值
百分比
770.00000000000000000000,340.670000000000000000000,96.00000000000000000000,4400.56000000000000000000,109.89000000000000000000,109.00000000000000000000,37.00000000000000000000,
当前我正在使用查询从表中选择cast([Percent]作为小数(9,2))作为[Percent]",将导致
结果
770.00,340.67,96.00,4400.56,109.89,109.00,37.00,
我实际上想要的结果是:->
770,340.67,96,4400.56,109.89,109,37,
您可以结合使用DECIMAL和FLOAT.十进制先将其四舍五入到2个十进制位置,然后浮动以删除不需要的0
例如
将演员表(cast([百分比]作为十进制(9,2))作为浮点数)选择为[百分比]
以340.69999999999999为例,首先将其舍入为340.70,然后将零取为340.7.像任何舍入一样,都会失去一些精度.
I want to ask if anybody know the query to drop the 0 value in decimal..
E.g : A field name percent have these values
Percent
770.00000000000000000000,340.670000000000000000000,96.00000000000000000000,4400.56000000000000000000,109.89000000000000000000,109.00000000000000000000,37.00000000000000000000,
Currently I'm using the query "select cast([Percent] as decimal(9,2)) as [Percent] from table" and will result in
Result
770.00,340.67,96.00,4400.56,109.89,109.00,37.00,
I want the result this actually:->
770,340.67,96,4400.56,109.89,109,37,
You could use a combination of DECIMAL and FLOAT. Decimal first to round it down to 2 deciaml places, then float to remove unwanted 0's
e.g.
select cast(cast([Percent] as decimal(9,2)) AS FLOAT) as [Percent]
With the example of 340.69999999999999, first it round to 340.70, then it takes away the zero giving you 340.7. As with any rounding some precision will be lost.
这篇关于将0值放在小数位的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!