In Android is there an easy way to insert commas into a numberical value? ie if I have an EditText with 12345 in it, how can I display this as 12,345?
I think I can do it using substring and chopping it up into x number of 3 number chunks then concatenating the answer with ',' between each 3 number chunk. This would be pretty easy if length of number was constant, but as the number could be from one digit to, say 20, it makes it more complex.
Just curious if there is a simple and clean way to achieve this before I go about making my substring solution.
Cheers
If Java --
Use something like this:
double amount = 2324343192.015;
NumberFormat formatter = new DecimalFormat("###,###,###.##");
System.out.println("The Decimal Value is: "+formatter.format(amount));
Result: The Decimal Value is: 2,324,343,192.02
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With