4

How can i use Locale setting to know decimal separator?

I read on net that -

The Salesforce locale settings determine the following display formats:
 * Date and time
 * Users’ names
 * Addresses
 * Commas and periods in numbers
but did not get any example how do we get decimal separator using Locale in apex.

Right now all floating point values are using . but we want to use separator as per Locale.

Like -

If the Locale settings in salesforce are changed to Swedish then number should display like = 500,2658.

If the Locale settings in salesforce are changed to USthen number should display like = 500.2658.

How can i achieve this in apex

3
1

if you use the following functions in SOQL queries, it will support localized result

SELECT statements can include the toLabel() and convertCurrency() functions in support of localized fields.

toLabel():

Use toLabel() on regular, multi-select, division, or currency code picklist fields (any field that has picklist values returned by the relevant describe call), data category group and data category unique name fields or RecordType names. Any organization can use toLabel(). It is particularly useful for organizations that have the Translation Workbench enabled. For example:

SELECT Company, toLabel(Recordtype.Name) FROM Lead

This query returns lead records with the record type name translated into the language for the user who issued the query.

convertCurrency():

If an organization is multicurrency enabled, you can use convertCurrency() in the SELECT clause to convert currency fields to the user's currency. Use this syntax for the SELECT clause: convertCurrency(field) For example:

SELECT Id, convertCurrency(AnnualRevenue) FROM Account

If an organization has enabled advanced currency management, dated exchange rates will be used when converting currency fields on opportunities, opportunity line items, and opportunity history. For more information, check the SOQL documentation in salesforce

0

Just in case somebody comes in this thread looking for an option, I've found out a workaround.

The Decimal class owns a method call .format(). This method turns the decimal value into a string with the format of the local currency.

In VF, you'd have this:

   <div>
      <p class="sq-txt bold">{!totalInvestmentCurrency} €</p>
   </div>

and in your Apex Controller just this:

    public String totalInvestmentCurrency {get;set;}

    totalInvestment= globalInvestmentPPC(centroCoste);
    totalInvestmentCurrency=totalInvestment.format();

My globalInvestmentCurrency returns a number in DECIMAL format. Which is the right one when it comes to working with currencies. I hope this helps!

This is the result in my VF page:

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.