Java – intentional loss of precision
•
Java
When converting double to int:
double d = 5.5; int i = (int) d;
Variable "I" becomes 5 This is exactly what I want. The problem is that I received a warning: converting from 'double' to 'Int' may lead to precision loss. My question is, is there any way to tell the IDE that this precision loss is expected, so I won't be warned? Is there any other way to lose precision and convert it to an integer?
I know I can completely disable all lost precision warnings, but it won't be good I'm using IntelliJ idea 13
Solution
The best thing is to use double and integer Then you can use the intvalue () method
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码