1

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
  • 665
  • 1
  • 7
  • 20

2 Answers2

0
int roundedBalance = Integer.parseInt(getString("balance").split(".")[0]);
Gex
  • 1,942
  • 18
  • 25
0

Do you want to remove the following points or numbers?

If only the points why not:

balance = balance.replace(".","");
johni07
  • 731
  • 1
  • 11
  • 29