日期:2014-05-18 浏览次数:20567 次
DECLARE @f1 FLOAT SET @f1 = 1.575 SELECT @f1 , ROUND(@f1, 2) DECLARE @f2 FLOAT SET @f2 = 1.475 SELECT @f2 , ROUND(@f2, 2) DECLARE @f3 FLOAT SET @f3 = 1.275 SELECT @f3 , ROUND(@f3, 2)
DECLARE @f1 decimal(18,2) SET @f1 = 1.575 SELECT @f1 , ROUND(@f1, 2) DECLARE @f2 decimal(18,2) SET @f2 = 1.475 SELECT @f2 , ROUND(@f2, 2) DECLARE @f3 decimal(18,2) SET @f3 = 1.175 SELECT @f3 , ROUND(@f3, 2) --/////////////////// DECLARE @f1 numeric(18,2) SET @f1 = 1.575 SELECT @f1 , ROUND(@f1, 2) DECLARE @f2 numeric(18,2) SET @f2 = 1.475 SELECT @f2 , ROUND(@f2, 2) DECLARE @f3 numeric(18,2) SET @f3 = 1.175 SELECT @f3 , ROUND(@f3, 2)
------解决方案--------------------
float 本身就是近似值,用decimal,如果保证小数点位数不超过4位,money是不二的选择
------解决方案--------------------
问题出在float类型上,float本身存储数据就是不准确的,你赋值是1.575可能实际上是1.574768655.。。建议使用DECIMAL类型的存储
------解决方案--------------------
DECLARE @f1 FLOAT
SET @f1 = 1.575
SELECT @f1-- ,ROUND(@f1, 2)
DECLARE @f2 FLOAT
SET @f2 = 1.475
SELECT @f2-- , ROUND(@f2, 2)
DECLARE @f3 FLOAT
SET @f3 = 1.275
SELECT @f3 --,ROUND(@f3, 2)
/*
-----------------------------------------------------
1.575
(所影响的行数为 1 行)
-----------------------------------------------------
1.4750000000000001
(所影响的行数为 1 行)
-----------------------------------------------------
1.2749999999999999
(所影响的行数为 1 行)
------解决方案--------------------