-3

Eg: I divide manually 8/3 = 2.666666.

When I divide in Java, I've got 8/3 = 2.0 instead.

How can I get the answer to display 2.667 or 2.67?

Thank you.

Riadh Belkebir
  • 739
  • 1
  • 11
  • 33
Ina
  • 47
  • 5
  • Most people do integer division in primary school before fractions and decimals, but they seem to forget it. How do you explain to a Grade 4 student that they should remember this when they start learning Java in 10+ years. ;) – Peter Lawrey Jun 29 '16 at 09:13

1 Answers1

1

You are doing integer division hence result is integer

you need to do ((double)8)/3 to get desired result

Sanjeev
  • 9,741
  • 2
  • 19
  • 33