Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I convert numbers to currency format in android

Tags:

android

I want to show my numbers in money format and separate digits like the example below:

1000 -----> 1,000

10000 -----> 10,000

100000 -----> 100,000

1000000 -----> 1,000,000

Thanks

like image 772
nazanin Avatar asked Aug 09 '17 13:08

nazanin


People also ask

How do you convert numbers to money format?

On the Home tab, click the Dialog Box Launcher next to Number. Tip: You can also press Ctrl+1 to open the Format Cells dialog box. In the Format Cells dialog box, in the Category list, click Currency or Accounting. In the Symbol box, click the currency symbol that you want.

How do I convert currency to string?

string value = (Convert. ToDecimal(ReturnValue)). ToString("c");


2 Answers

Another approach :

NumberFormat format = NumberFormat.getCurrencyInstance(); format.setMaximumFractionDigits(0); format.setCurrency(Currency.getInstance("EUR"));  format.format(1000000); 

This way, it's displaying 1 000 000 € or 1,000,000 €, depending on device currency's display settings

like image 147
Thomas Mary Avatar answered Oct 15 '22 02:10

Thomas Mary


You need to use a number formatter, like so:

NumberFormat formatter = new DecimalFormat("#,###"); double myNumber = 1000000; String formattedNumber = formatter.format(myNumber); //formattedNumber is equal to 1,000,000 

Hope this helps!

like image 34
dFrancisco Avatar answered Oct 15 '22 02:10

dFrancisco