-2

I want to print float values as an integer that is if the value is 70.0 then 70 and but if it is 70.1 then it should not change into int value as 70.1?

1 Answers1

0

You can use BigDecimal for your values and call method stripTrailingZeros() to remove zeros.

You can check it:

new BigDecimal("15.00").stripTrailingZeros();

will return:

15

And for float value:

new BigDecimal("15.1").stripTrailingZeros();

Will return:

15.1
wojdzie
  • 51
  • 2