0

I want to make simple subtract operation on float so that I don't get a final decimal but I got same result with float

Better than my bad english : code !

    private double test(final double reloadingTime) {
    double timeRestant = reloadingTime - 0.1;
    System.out.println(timeRestant);
    return timeRestant;
}

main :

    double test = test(2f);
    test = test(test);
    test = test(test);
    test = test(test);
    test = test(test);
    test = test(test);

console :

1.9
1.7999999999999998
1.6999999999999997
1.5999999999999996
1.4999999999999996
1.3999999999999995

So two questions: Why? And how can I can get the true result?

sfjac
  • 7,119
  • 5
  • 45
  • 69
fabiitch
  • 41
  • 1
  • 3

0 Answers0