← Unit 1 · all exercises
Saved in this browser only

Chop off the decimals

Return the whole-number part of the value, throwing away anything after the decimal point. 9.99 becomes 9, and -2.7 becomes -2. This is what a cast does — it does not round.

int wholePart(double value)

Solution.java
Loading editor…
Results

Examples

  • wholePart(9.99) → 9
  • wholePart(4) → 4

There are also 3 hidden tests you can't see. Solve the problem, not the examples.