Search code examples
javaandroidends-with

Need endswith dot and one number


I need the conditional if my number inserted in an EditText ends with dot+any number. Example:

129.2

if ends with this, need that the new value like this.

192.20

thanks in advance.


Solution

  • why not using a NumberFormat for the output?

    double a = 123.2;       
    NumberFormat formatter = new DecimalFormat("#0.00");
    String aFormat = formatter.format(a);
    System.out.println(aFormat); // --> 123.20
    

    So you can easyly change you preferend output format. More info: NumberFormat - Android