Ajay Gujja
Ajay Gujja

Reputation: 99

How to format Number of json object and set it in TextView Android

I'm Developing an app that fetches data from JSON. I want to set the int number into TextView in Formatted Way. I used Java java.text.NumberFormat for Formating.I want data to be Like 100000 = 1,00,000.

But This Giving error

java.lang.IllegalArgumentException: Cannot format given Object as a Number

Here is my code

 String myString = NumberFormat.getCurrencyInstance().format(jsonObject.getString("cases"));
 totalCasesNum.setText(myString);

Upvotes: 0

Views: 290

Answers (1)

Dan M
Dan M

Reputation: 4377

Try this:

String myString = NumberFormat.getCurrencyInstance().format(Integer.parseInt(jsonObject.getString("cases"));

Upvotes: 1

Related Questions