浮点数 [英] float numbers

查看:145
本文介绍了浮点数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨!


如何让t-sql不能舍入我返回的结果?


例如:

0.9616458 * 60 = 57,698748(在任何计算器中)


以下:

-------- ------------------------

声明@a float

声明@b int


设定@ a = 0.9616458

设定@ b = 60


打印@ a * @ b

---------------------------------

将显示:57.6987


如何让MSSQL向我展示它的价值呢?


谢谢!

解决方案

使用SELECT:


选择@ a * @ b


- -

汤姆


---------------------------- ------------------------

Thomas A. Moreau,理学士,博士,MCSE,MCDBA

SQL Server MVP

加拿大多伦多

..

< ho ** @ havet.se>在留言中写道

news:11 ********************** @ g10g2000cwb.googlegr oups.com ......

嗨!


如何让t-sql不能舍入我返回的结果?


例如:

0.9616458 * 60 = 57,698748(在任何计算器中)


跟随:

------- -------------------------

声明@a float

声明@b int


设定@ a = 0.9616458

设定@ b = 60


打印@ a * @ b

---------------------------------

将显示:57.6987


如何让MSSQL向我显示其四舍五入的价值?


谢谢!


嗨!尝试了你的代码,它在我给出的例子中工作得很好,但是当我在我的代码中实现它时没有




声明@x float(53)

声明@grades int

声明@minutes int

声明@seconds浮动(53)

声明@minwithrest浮动(53)

声明@leftover浮动(53)


选择@x = 57.66602743

选择@grades = floor(@ x)

选择@leftover = @ x- @ grade

选择@minwithrest =(@ leftover * 60)

选择@minutes = floor (@minwithrest)

选择@seconds =(@ minwithrest - @minutes)* 60


print @分钟

打印@seconds

给我57.6987作为@秒,而它应该是57,698748


谢谢!


抱歉。我的意思是它给了我57.698747999999114它应该是

57,698748。

(打印被选择取代)


Hi!

How do I do to make t-sql not rounding the result that i returned?

For example:
0.9616458*60 = 57,698748 (in any calculator)

while following:
--------------------------------
declare @a float
declare @b int

set @a=0.9616458
set @b=60

print @a*@b
---------------------------------
will show :57.6987

How do I do to make MSSQL to show me the value whothout rounding it?

Thanks!

解决方案

Use SELECT:

select @a*@b

--
Tom

----------------------------------------------------
Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
SQL Server MVP
Toronto, ON Canada
..
<ho**@havet.se> wrote in message
news:11**********************@g10g2000cwb.googlegr oups.com...
Hi!

How do I do to make t-sql not rounding the result that i returned?

For example:
0.9616458*60 = 57,698748 (in any calculator)

while following:
--------------------------------
declare @a float
declare @b int

set @a=0.9616458
set @b=60

print @a*@b
---------------------------------
will show :57.6987

How do I do to make MSSQL to show me the value whothout rounding it?

Thanks!


Hi! Itried your code and it works fine in the example I gave but not
when I implement it in my code:

declare @x float(53)
declare @grades int
declare @minutes int
declare @seconds float(53)
declare @minwithrest float(53)
declare @leftover float(53)

select @x = 57.66602743
select @grades = floor(@x)
select @leftover = @x-@grades
select @minwithrest = (@leftover * 60)
select @minutes = floor(@minwithrest)
select @seconds = (@minwithrest - @minutes) * 60

print @grades
print @minutes
print @seconds
gives me 57.6987 as @seconds while it should be 57,698748

thanks!


sorry. I meant that it gives me 57.698747999999114 and It should be
57,698748 .
(The print is replaced by select)


这篇关于浮点数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆