That’s because 1
and 3
are treated as integers
when you don’t specify otherwise, so 1/3
evaluates to the integer
0
which is then cast to the double
0
. To fix it, try (1.0/3)
, or maybe 1D/3
to explicitly state that you’re dealing with double values.
More Related Contents:
- why i multiply many number make a mistake when i division?
- The main thing is: how that binary for example 11110000 is divided into two parts such as s1=1111 and s2=0000. I have to do this in Java
- Why does integer division code give the wrong answer? [duplicate]
- Simple division in Java – is this a bug or a feature?
- Division in Java always results in zero (0)? [duplicate]
- Why does (360 / 24) / 60 = 0 … in Java
- Why does dividing a float by an integer return 0.0?
- ArithmeticException thrown during BigDecimal.divide
- Why is Java’s division broken?
- Unexpected result in long/int division
- Integer division in Java [duplicate]
- (a * b) / c MulDiv and dealing with overflow from intermediate multiplication
- String class replace() method [closed]
- Convert a string representation of a hex dump to a byte array using Java?
- NoSuchMethodError in javax.persistence.Table.indexes()[Ljavax/persistence/Index
- Convert a JSON String to a HashMap
- How to capitalize the first letter of a String in Java?
- Java Generate Random Number Between Two Given Values [duplicate]
- Android M Permissions: onRequestPermissionsResult() not being called
- Change global setting for Logger instances
- How can I set date and time formatting in Java that respects the user’s OS settings
- Java game loop (painting) freezes my window
- How to solve maven 2.6 resource plugin dependency?
- Bug in eclipse compiler or in javac (“type parameters of T cannot be determined”)
- Changing the default XML namespace prefix generated with JAXWS
- GZip POST request with HTTPClient in Java
- What are the differences between perl and java regex capabilities?
- How to configure trustStore for javax.net.ssl.trustStore on windows?
- Using Gson with Interface Types
- Jackson Serialize Instant to Nanosecond Issue