Search code examples
androidnumbersdoubledecimallimit

How to limit decimal digits - Android


I already searched online and all that I found is using DecimalFormat and I tried it, but when I code on Android Studio, appears a message saying that is necessary to use the API 24 to this kind of command. The API 24 has erros and all the sites I looked, advised to use the API 23.

So, I need a way to show double numbers only with two decimal digits on my AlertDialog.


Solution

  • referring to this SO post, you can use this code:

    String formattedValue = String.format("%.2f", myDouble);
    

    Let me know if it is what you were looking for