Forums
New posts
Search forums
Members
Current visitors
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
Forums
Archive
Archive
Java
question regarding java puzzlers #2
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
[QUOTE="Stefan Ram, post: 2838159"] The floating point values are represented as binary floating point values. /Binary/ floating point values can not exactly represent all values, even if those value have a short exact representation using the decimal system. For example, the value of the decimal numeral »0.1« can not be represented as a finite binary fraction. So, when it is represented, the true representation with infinitely many binary digits needs to be abbreviated to finitely many digits. The error becomes visible, when such a value then is converted back to a decimal representation. public class Main { public static void main( final java.lang.String[] args ) { java.lang.System.out.println( new java.math.BigDecimal( 0.1 )); }} 0.1000000000000000055511151231257827021181583404541015625 So, then, the next question to ask would be: Why does the following program not print »0.1000000000000000055511151231257827021181583404541015625«, but »0.1« instead? public class Main { public static void main( final java.lang.String[] args ) { java.lang.System.out.println( 0.1 ); }} 0.1 [/QUOTE]
Verification
Post reply
Forums
Archive
Archive
Java
question regarding java puzzlers #2
Top