Two Laptop Bag
The moose likes Beginning Java and the fly likes Java double data type problem Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "Java double data type problem" Watch "Java double data type problem" New topic
Author

Java double data type problem

Rameshwar Soni
Ranch Hand

Joined: Feb 03, 2011
Posts: 246
Can anyone please explain me the output of the following program??? Thanks in advance
Jesper de Jong
Java Cowboy
Bartender

Joined: Aug 16, 2005
Posts: 12907
    
    3

The notation for octal number literals, starting with 0, is only for integers.

020 is an integer literal, so it is interpreted as an integer with the decimal value 16, which you then assign to a double, so that the int gets converted to a double.

020.0 is not an octal floating-point literal. It's a decimal floating-point literal; that's why you see the value 20.0 (decimal) printed. A leading 0 when writing a floating-point literal does not mean that the notation is octal.

Look at section 3.10.1 and 3.10.2 of the Java Language Specification for the exact details.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: Java double data type problem
 
Similar Threads
Integer decode() vs. valueOf()
Explanation needed for this program
Trouble with BigDecimal and Double
1) double variable storing hexadecimal value 2) catching runtime exception
Wrapper class