I have a very simple lightning component taken straight from the aura docs that on initialization sets an attribute to a percentage. I noticed that the localization service rounds the value as opposed to adding a decimal according the scale of the percentage. This was noticed when using it in a more complex component where decimal points are required.
If decimals were included, the formats would be different.
US format = XX.X% French format = XX,X%
I do not see a param in the Aura documentation for adding scale and the CLDR states that there are patterns that have a percent leading, with most cases having the sign trailing: http://www.unicode.org/cldr/charts/30/by_type/numbers.number_formatting_patterns.html
The component and the two variations of the controller:
<aura:component >
<aura:handler name="init" value="{!this}" action="{!c.doInit}"/>
<aura:attribute name="percent" type="string" />
<ui:outputText value="{!v.percent}" />
Controller - returns 54%:
({
doInit: function(component) {
var num = 0.5444
// Returns 54%
var formatted = $A.localizationService.formatPercent(num);
component.set("v.percent", formatted);
}
})
Controller - returns 55%:
({
doInit: function(component) {
var num = 0.5456
// Returns 55%
var formatted = $A.localizationService.formatPercent(num);
component.set("v.percent", formatted);
}
})