I have a string value as below:
String percValue = "0.0209"
How can I convert this to something like as below
String formatedValue = "2.09%";
Can someone help me what is the simple and best way to convert this?
One good way would be to:
double type variable, so it can hold the decimal places...),String percValue = "0.0209";
double percentage = Double.parseDouble(percValue) * 100;
String formattedValue = String.format("%.2f%%", percentage);
Explanation:
Double.parseDouble() takes your string as a parameter and returns a double value which you can do things like multiplication and addition with, and String.format() lets you precisely control how your number is converted back to a String! If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With