moltam89/liferay-portal — pull request #132 by lipusz (2013-05-03 12:05:09+00:00)
Title: [TECHNICAL-SUPPORT] LPS-34842 Polls Display & Polls control panel portlets - Percentage field contains extra spcace on French locales (fr_CA, fr_FR)

Hi Tamás,

The problem is NumberFormat formats the arguments based on the locale in which it was instantiated for.
In French locales, there will be an extra space between the digits and the symbols for percentage.

You can test it easily by creating this simple Java class:

package com.liferay.mytest;

import java.text.NumberFormat;
import java.util.Locale;

public class Main {

public static void main(String args[]) {

NumberFormat enFormat = NumberFormat.getPercentInstance(
Locale.ENGLISH);

NumberFormat frFormat = NumberFormat.getPercentInstance(
Locale.FRENCH);

double percent = 0.53;

// output: 53%
System.out.println(enFormat.format(percent));

// output: 53 %
System.out.println(frFormat.format(percent));
}
}

Unfortunately, I couldn't find a way to avoid this format, so I've added a new CSS class to the main.css files of Polls & Polls Display portlets to prevent wrapping (line-break) these values because of the extra spaces.

I've applied it to both "percentFormat.format(votesPercent)" & "numberFormat.format(choiceVotes)", because the latter one also can be problematic, if there are at least 1000 votes, and the "thousand" separator is space, e.g. "1 0000"

Please, review my changes.

Thanks,
Tibor

==
Site note:
http://stackoverflow.com/questions/698261/how-do-you-format-a-fractional-percentage-with-java-text-messageformat

String formatted = MessageFormat.format("{0, number,#.#%}", percent);
// output: 53%
System.out.println(formatted);

But I don't think it's the best solution.