Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make a number format?

Tags:

java

android

I want to format number which I receive from the local database

Example:

10000 to 10.000 or 1000000 to 100.000

My code:

holder.mTextViewHarga.setText("Rp. " + mProdukList.get(position).gethargaProduk());

i have to try this code before but still error:

Locale localeID = new Locale("in", "ID");
NumberFormat formatRupiah = NumberFormat.getCurrencyInstance(localeID);

holder.mTextViewHarga.setText("Rp. " +formatRupiah.format((double) mProdukList.get(position).gethargaProduk()));
like image 795
Pasek Beratha Avatar asked Oct 21 '25 12:10

Pasek Beratha


1 Answers

Use DecimalFormat()

DecimalFormat df2 = new DecimalFormat( "#,###,###,##0.00" );
double d = 100.2397;
double d1 = new Double(df2.format(d)).doubleValue();

Output - d1 will be 100.24

like image 65
Ismail Avatar answered Oct 24 '25 01:10

Ismail



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!