2

So, I have two numbers as strings - for example, 123.00 and 123.50. How do I remove the decimal point and all that follows. I had a method that worked for the 123.00, but would not work correctly on the 123.50.

Here is what I have so far:

    String balance = getString("balance");

    BigDecimal number = new BigDecimal(balance);

    String formattedBalance = number.stripTrailingZeros().toPlainString();

    int roundedBalance = Integer.parseInt(formattedBalance);
AndroidDev21921
  • 695
  • 1
  • 8
  • 21

2 Answers2

0
int roundedBalance = Integer.parseInt(getString("balance").split(".")[0]);
Gex
  • 2,092
  • 19
  • 26
0

Do you want to remove the following points or numbers?

If only the points why not:

balance = balance.replace(".","");
johni07
  • 761
  • 1
  • 11
  • 31