在sql查询中使用bigint时得到错误的结果

时间:2021-11-03 17:00:11

I have passed below AmountDue in query but am getting wrong result. AmountDue data type is Float.

我在查询中传递了AmountDue,但结果错了。 AmountDue数据类型为Float。

AmountDue: 2412880.28
AmountDue: 561.06

My query:

我的查询:

select CONVERT(varchar,(select convert(bigint,AmountDue*100)))
from dbo.tblBidResults

I am getting below results which is wrong:

我得到的结果是错误的:

241288027
56105

Correct Result:

正确的结果:

241288028
56106

2 个解决方案

#1


1  

try converting to numeric instead of bigint:

尝试转换为数字而不是bigint:

DECLARE @temp float
set @temp = 2412880.28
SELECT CONVERT(varchar,(CONVERT(numeric(27,0),@temp*100)))

There is a good post that goes over the reason for this here.

有一篇好文章说明了这里的原因。

#2


1  

DECLARE @temp float
set @temp = 2412880.28
select convert(varchar,convert(decimal(9,0),@temp*100))

SQL FIDDLE

SQL FIDDLE

#1


1  

try converting to numeric instead of bigint:

尝试转换为数字而不是bigint:

DECLARE @temp float
set @temp = 2412880.28
SELECT CONVERT(varchar,(CONVERT(numeric(27,0),@temp*100)))

There is a good post that goes over the reason for this here.

有一篇好文章说明了这里的原因。

#2


1  

DECLARE @temp float
set @temp = 2412880.28
select convert(varchar,convert(decimal(9,0),@temp*100))

SQL FIDDLE

SQL FIDDLE