Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
3.8k views
in Technique[技术] by (71.8m points)

为什么要除100.1,除100得到的结果为什么不对?

如题,例子如下:
image.png
感谢解答!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

因为有的程序语言 整数之间进行四则运算,结果也会是整数。这时候如果结果运算为小数,会向下取整。

除于100.1 则是整数与小数计算,会先将另一个操作数12转为小数12.0,这样就是小数与小数的计算,结果是小数。

其实并不是非得100.1, 100.0也可以得到正确结果。


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...