This question has already been answered:

I forgot. 360 * x / 100 where the type is x float, the result on the calculator is 0.0895522392 in the program gives 0.08955224, why did he cut me like that?

Reported as a duplicate by participants 0xdb , Kromster , pavlofff java Mar 30 '18 at 6:18 .

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 .

  • Use double - Kirill Malyshev
  • Float fewer decimal places? ... - Alexandr
  • 2
    float - 4 bytes, double - 8, less bytes - less accuracy - Uraty

1 answer 1

If you want complete control over calculations, use specialized types, instead of built-in

For example:

public static void main(String[] args) { float x = 0.024875622f; int scale = 10; System.out.println(new BigDecimal(360).multiply(new BigDecimal(x)).divide(new BigDecimal(100), scale, RoundingMode.FLOOR)); }