Skip to content Skip to sidebar Skip to footer

Format Price In 0.00 Format In Android Using Edittext

I am trying to mask a price value so that it is always in 0.00 format. Here is my code float temp = 0; DecimalFormat mDecimalFormat = new DecimalFormat('###.00'); @Override publi

Solution 1:

Recommended way of formatting currency and prices:

    Locale loc = Locale.getDefault();
    NumberFormat nf = NumberFormat.getCurrencyInstance(loc);
    nf.setCurrency(Currency.getInstance(loc));
    nf.setMaximumFractionDigits(2);
    nf.setMinimumFractionDigits(2);

    System.out.println(nf.format(23.5634));
    System.out.println(nf.format(0.5));

Solution 2:

use String.format

String.format("$%.2f", result);

or

   Strint text = String.format("$%.2f", addNumber(temp));
   mMasEditText.setText(text)

Post a Comment for "Format Price In 0.00 Format In Android Using Edittext"