Jayyanthii Thakur
Jayyanthii Thakur

Reputation: 261

How to Apply mask to string value

i want to apply format mask like "#0" to my number field which is string like "6000", i tried different types of formatting,but it didnt help,can anyone 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 the formatted output 6,000.00

Upvotes: 3

Views: 2287

Answers (2)

jlordo
jlordo

Reputation: 37813

This should help:

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

Upvotes: 2

Ridcully
Ridcully

Reputation: 23655

Just convert your string "6000" to a number e.g.

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

Then use DecimalFormat like explained here: How do I format a number in Java?

Upvotes: 0

Related Questions