[SalesForce] How to use locale settings for decimal separator

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

Best Answer

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

Related Topic