分数的可能损失 [英] Possible Loss of Fraction
本文介绍了分数的可能损失的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
原谅我,如果这是幼稚的问题,但今天我很茫然。
Forgive me if this is a naïve question, however I am at a loss today.
我有一个简单的除法计算,如如下:
I have a simple division calculation such as follows:
double returnValue = (myObject.Value / 10);
值是在对象一个int。
Value is an int in the object.
我得到一个消息,说分数的可能损失。然而,当我换双为int,此消息消失。
I am getting a message that says Possible Loss of Fraction. However, when I change the double to an int, the message goes away.
这是为什么会发生这种事有什么想法?
Any thoughts on why this would happen?
推荐答案
当你把两个int的成浮点值的小数部分丢失。如果你投的项目之一为float,你不会得到这个错误。
When you divide two int's into a floating point value the fraction portion is lost. If you cast one of the items to a float, you won't get this error.
因此,例如把10到10.0
So for example turn 10 into a 10.0
double returnValue = (myObject.Value / 10.0);
这篇关于分数的可能损失的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文