Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Inserting commas into integers

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

like image 530
Entropy1024 Avatar asked Nov 18 '10 22:11

Entropy1024


1 Answers

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

like image 153
Griff Avatar answered Sep 27 '22 20:09

Griff