为什么1.4 - 0.5会导致0.8999999999999999? [英] Why does 1.4 - 0.5 result in 0.8999999999999999?

查看:107
本文介绍了为什么1.4 - 0.5会导致0.8999999999999999?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用IE 6.0并在javascript中进行一些计算。


如果我运行此代码:

alert(1.4 - 0.5);


i得到的结果是0.8999999999而不是0.9

有人知道为什么吗?这是IE中的错误还是什么?任何快速简便的方法可以解决这个问题吗?


BR

公爵

解决方案

2004年6月2日02:04:54 -0700,Fredrik Celin写道:

我得到的结果是0.8999999999而不是0.9




< http://www.jibbering.com/faq/#FAQ4_7>


-

Andrew Thompson
http://www.PhySci.org/开源软件套件
http://www.PhySci.org/codes / Web& IT帮助
http://www.1point1C.org/ Science&技术


在文章< fb ************************** @发布。 google.com>,Fredrik

Celin< fr *********** @ bilia.se>写道:

我使用IE 6.0并在javascript中进行一些计算。

如果我运行此代码:
alert(1.4 - 0.5) ;

我得到的结果是0.8999999999而不是0.9

有人知道为什么吗?这是IE中的错误还是什么?任何快速简便的方法来解决这个问题?

B.R
公爵



计算机使用二进制进行计算。有些分数不会直接转换为
。我的建议总是四舍五入到小数位数
需要



-

Dennis Marks
http://www.dcs-chico.com/~denmarks/

回复电子邮件地址的邮件将被退回。

访问网站以获取有效的电子邮件地址。

----- =已发布通过Newsfeeds.Com,未经审查的Usenet新闻= -----
http:// www。 newsfeeds.com - 世界排名第一的新闻组服务!

----- ==超过100,000个新闻组 - 19个不同的服务器! = -----


" Fredrik Celin" < FR *********** @ bilia.se>在消息中写道

news:fb ************************** @ posting.google.c om ...

我使用IE 6.0并在javascript中进行一些计算。

如果我运行此代码:
alert(1.4 - 0.5);

我得到的结果是0.8999999999而不是0.9

有人知道为什么吗?这是IE中的错误还是什么?任何快速简便的方法来解决这个问题?




计算机不计算,抱歉任何混乱。他们可以在

内存中存储一​​个数字,或者从内存中检索一个数字。他们还可以添加一个数字,

或从数字中减去一个。他们还可以在另一个号码上添加一个号码。

就是这样。


-

Mabden


I use IE 6.0 and does some calculations in a javascript.

If I run this code:
alert(1.4 - 0.5);

i get the result 0.8999999999 and not 0.9
Does anybody know why? Is this a bug in IE or what? Any fast and easy
ways to work around this problem?

B.R
The Duke

解决方案

On 2 Jun 2004 02:04:54 -0700, Fredrik Celin wrote:

i get the result 0.8999999999 and not 0.9



<http://www.jibbering.com/faq/#FAQ4_7>

--
Andrew Thompson
http://www.PhySci.org/ Open-source software suite
http://www.PhySci.org/codes/ Web & IT Help
http://www.1point1C.org/ Science & Technology


In article <fb**************************@posting.google.com >, Fredrik
Celin <fr***********@bilia.se> wrote:

I use IE 6.0 and does some calculations in a javascript.

If I run this code:
alert(1.4 - 0.5);

i get the result 0.8999999999 and not 0.9
Does anybody know why? Is this a bug in IE or what? Any fast and easy
ways to work around this problem?

B.R
The Duke


Computers use binary for computations. Some fractions do not convert
exactely. My advice is always round off to the number of decimal places
required.

--
Dennis Marks
http://www.dcs-chico.com/~denmarks/
Mail to the return email address is bounced.
Go to web site for active email address.
-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----== Over 100,000 Newsgroups - 19 Different Servers! =-----


"Fredrik Celin" <fr***********@bilia.se> wrote in message
news:fb**************************@posting.google.c om...

I use IE 6.0 and does some calculations in a javascript.

If I run this code:
alert(1.4 - 0.5);

i get the result 0.8999999999 and not 0.9
Does anybody know why? Is this a bug in IE or what? Any fast and easy
ways to work around this problem?



Computers don''t compute, sorry for any confusion. They can store a number in
memory, or retrieve a number from memory. They can also add one to a number,
or subtract one from a number. They can also add a number to another number.
That''s about it.

--
Mabden


这篇关于为什么1.4 - 0.5会导致0.8999999999999999?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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