fork(1) download
  1. class Example
  2. {
  3. private static int specialRounding(double myValue) {
  4. int base = (int)Math.floor(myValue);
  5. double remainder = myValue - base;
  6. int intValue = remainder >= .8 ? base + 1 : base;
  7. return intValue;
  8. }
  9. private static void test(double myValue) {
  10. System.out.println(myValue + " => " + specialRounding(myValue));
  11. }
  12. public static void main (String[] args) throws java.lang.Exception
  13. {
  14. test(0.999);
  15. test(0.8);
  16. test(0.79);
  17. }
  18. }
Success #stdin #stdout 0.05s 4386816KB
stdin
Standard input is empty
stdout
0.999 => 1
0.8 => 1
0.79 => 0