How to apply a mask to a string value

I want to apply a format mask like โ€œ# 0โ€ to my number field, which is a string like โ€œ6000โ€, I tried various types of formatting, but it didnโ€™t help, can someone tell me how to handle this in android, please

I am looking for something like when I do this formatString("6000", "#,##0.00") , it should give me formatted output of 6,000.00

+4
source share
2 answers

This should help:

  String yourString = "6000"; double value = Double.valueOf(yourString); DecimalFormat df = new DecimalFormat("#,##0.00"); System.out.println(df.format(value)); 
+2
source

Just convert the string "6000" to a number, for example.

 double d = Double.parseDouble("6000"); 

Then use DecimalFormat as described here: How do I format a number in Java?

0
source

All Articles