This question has already been answered:

double i = 100 / 3; float j = 100 / 3; System.out.println(i); System.out.println(j); 

Returns: 33.0

Why not 33.3?

Reported as a duplicate by participants Alexey Shimansky , Anton Shchyrov , Nofate java Nov 22 '17 at 12:50 pm

A similar question was asked earlier and an answer has already been received. If the answers provided are not exhaustive, please ask a new question .

  • one
    Somewhere around here are a bunch of duplicates about integer division - Alexey Shimansky
  • Because not double i = 100 / 3.0; . - kot-da-vinci

1 answer 1

In java division of two integers in the result returns an integer.

By this, the 100/3 division is first performed and it is 33 . And only then the conversion to the double type occurs and it turns out 33.0

For the result you want, you can divide it like this:

 double i = 100.0 / 3;