Double value returns 0 [duplicate]

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.

Leave a Comment