Remember
Register
All Activity
Tags
Users
Ask a Question
About Boostr
Advertise on boostr.in
Jobs
how to get the decimal part of a float using -'java,floating-point'
how to get the decimal part of a float Â using -'java,floating-point'
I need to extract the decimal part of a float number, but I get weird results:
float n = 22.65f;
// I want x = 0.65f, but...
x = n % 1; // x = 0.6499996
x = n - Math.floor(n); // x = 0.6499996185302734
x = n - (int)n; // x = 0.6499996
Why does this happen? Why do I get those values instead of 0.65?
Â Â Â Â
java
floating-point
asked
Sep 7, 2015
by
rajesh
Please
log in
or
register
to add a comment.
0
votes
2
views
Your answer
Your name to display (optional):
Email me at this address if my answer is selected or commented on:
Email me if my answer is selected or commented on
Privacy: Your email address will only be used for sending these notifications.
Anti-spam verification:
To avoid this verification in future, please
log in
or
register
.
...