6

If a user locale is set to ‘nl_NL’, the number format in output text will be 1.777,7 here decimal is not a real decimal.. and I am doing calculation on the above number...so is their standard function that can manage and change these numbers into the standard US number... like 17777 so that my calculations will be fine..

For e.g: in de-DE locale .. number id 1.223.333,00 after parse float it is converted into 1.223 something. However I need that de-DE to be into US format i.e 1,223,330.00 to make my calculation work.

What I need is: When I enter 1.777.777,00 (or any number in any locale) it should convert to en-US local format i.e 1,777,777.00. because I am doing some calculation and parsefloat function in javascript messing up the calculations.. Any help would be appreciated. Regards, Paddy

1 Answer 1

2

The <apex:outputText/> provides options to specify an output format for numbers. The available formatting options for it come from what is specified in the Java DecimalFormat documentation. It turns out that apex:outputText will actually not convert the comma separator in the format string to the locale specific separator.

Here's a simple example. I set the Org's locale and my User locale to Germany (Germany).

public with sharing class LocaleController {
    public Decimal getNumber() {
       return 1223333;
    }

    public String getNumberString() {
        // Decimal.format() specifies that return value is in user locale
        return getNumber().format();
    }
}

<apex:page controller="LocaleController">

    <!-- 1,223,333.00 is printed with comma separators -->
    <apex:outputText value="{0, number,###,###,###,###.00}">
        <apex:param value="{!number}" />
    </apex:outputText><br/>

    <!-- 1.223.333 is printed with dots -->
    {!numberString}  

</apex:page>

What's interesting is that the Java documentation states that the comma is a special character in the format string and will be converted to the locale specific format, yet it isn't in the apex:outputText.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .