I’ve created an age-in-minute calculator application. It’s all working fine but as the final results, age in minutes is shown, we get a very big number as a result(like 65536367) and it becomes difficult for the user to read it in a single go. So I want my app to show the final result to user with commas according to the Indian system(like 6,55,36,367).
My app is in Kotlin, please provide any useful ways to do so.
You can undoubtedly implement that using just a few lines of code
This task can be done using the “java.text.DecimalFormat” package
Let us assume that your number is in textview1:
In this line, I have defined a variable to store the text in String format
double amount = Double.parseDouble(number);
Now to use the package we need to convert this string value into double using explicit type casting
DecimalFormat formatted = new DecimalFormat("#,##,###.00");
In this line, your number will be converted into a format
#,##,###.00
if you want to ignore the decimal part you can use#,##,###
just this. It depends on how many digits of the number you want to format here I have assumed that the number is in lakhs. It’s better to keep the format at maximum digits because you don’t know what value the user will enter.String newnumber = formatter.format(amount);
Note to remember the final value returned won’t be an integer since it contains commas.
The new formatted number will be displayed in textview2
I hope this helps
Thank You