0

I am getting value in currency formate, but i want double format only.

String amt = txn.getAmount();
System.out.println("--amt--"+amt);//output:1010
double value = Double.parseDouble(amt);
System.out.println("---value---"+value);//output:1010.0
String ammount=NumberFormat.getCurrencyInstance().format(value);
System.out.println("--ammount--"+ammount);//output:Rs.1,010.00

Here i want Rs.1,010.00 to 1010.00

Any mistakes in my code?

Durga
  • 545
  • 7
  • 21
  • 39

3 Answers3

3

I assume you do not want the currency details. In that case, use getNumberInstance() instead of getCurrencyInstance().

Use:

NumberFormat nf = NumberFormat.getNumberInstance();
nf.setGroupingUsed(false);
nf.setMinimumFractionDigits(2);
String ammount= nf.format(value);
dev8080
  • 3,950
  • 1
  • 12
  • 18
0

Before printing, replace the string "Rs." with "" and also "," with "".

String replaceString1=amount.replace("Rs.","");
String replaceString2=amount.replace(",","");

This is a way to handle this case. Hope this helps.

Ria Sen
  • 94
  • 13
0

Try this cleaner approach!.

      double d = 1010.00;
      Locale uk = new Locale("en", "GB");
      NumberFormat cf = NumberFormat.getCurrencyInstance(uk);
      String s = cf.format(d);

      System.out.println(s);

      Number number = null;
      try
      {
         number = cf.parse(s);
      }
      catch (ParseException e)
      {
         System.out.print(e);
      }
      double dClone = number.doubleValue();
diyoda_
  • 5,274
  • 8
  • 57
  • 89