Formatting and Parsing a Locale-Specific Percentage

// Format
Locale locale = Locale.CANADA;
String string = NumberFormat.getPercentInstance(locale).format(123.45);
// 12,345%

// Parse
try {
    Number number = NumberFormat.getPercentInstance(locale).parse("123.45%");
    // 1.2345
    if (number instanceof Long) {
        // Long value
    } else {
        // Double value
    }
} catch (ParseException e) {
}

Post a comment

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Enter the characters shown in the image. Ignore spaces and be careful about upper and lower case.