You need to sign in to do that
Don't have an account?
JavaScript calculation based on locale
Hi All,
I have a use case in which user with different locale can access the VF page.
On this VF page I have some number calculation using JavaScript this number field are directly bind with SF object fields.
So whenever user with different locale access this page the bind number field display format is changed and result in improper calculation.
For example, a number that we would write in the US as "1,250,500.75" would be written differently in different countries: "1.250.500,75" in Germany, "1 250 500,75" in France, and "1'250'500.75" in Switzerland, and "125,0500.75" in Japan.
Any thoughts or workaround would be appreciated
Thanks in advance.
Offhand, without seeing any code, I'm guessing that you are using multi-currency. When you are using multi-currency, the end-user will always see currency values in their expected format, as long as you are using SFDC fields, either <apex:inputField> or <apex:outputField>. If you go off the reservation and use <apex:inputText> or even vanilla HTML inputs, then you are responsible for writing a whole lot of code.
If you are going to use Javascript instead of Visualforce, you may be able to find a JS library that helps - but I would just use VF. Keep in mind that you are going to have to discover what the user's actual locale is on their User record and adapt accordingly.
Good luck!
Thanks John.
Your understanding is correct. Its a multicurrency ORG and I am using javascript for calculation (for ex. price * quantity ) it works fine for US locale.This is because of parseFloat function which only support number which is in US number format i.e. 12,152.53.
If parseFloat function encounter other number format like German locale "1 250 500,75" in this case parsefloat only consider first digit and ignore other digits which result in improper calculation.
For this issue I found one JQuery globalize plugin. (https://github.com/jquery/globalize/downloads).
Can you share your thoughts on this ?
Thanks
FP
For e.g. For Dublin , 1.250.500,75 +1 ? what would be result? Expected 1250501.75 in the database..PLease confirm do the I get the expected result or not?
Or if not then how can I handle these calculation in Apex?
Thank you,
Paddy
Did you find any solution to your issue?
Thank you.
Paddy
https://github.com/jquery/globalize
I have played around with the examples and it seems to be great for the purpose. It supports dates, currencies, numbers and more.
It is not so easy to use because "Globalize needs CLDR content to function properly, although it doesn't embed, hard-code, or host such content. Instead, Globalize empowers developers to load CLDR data the way they want." But they explain how that works and all the CLDR data is also available.
----
For everybody interested in global date formatting features in Javascript I can recommend moment.js (http://momentjs.com).
Very easy to use for converting dates from one format to another and performing operations on dates eg add/substract time.
----
If you are interested in formatting plain numbers/dates to a certain locale format or currency the easiest way is to use Intl.js (the implementation of ECMAScript Internationalization API). Actually Intl.js is implemented in modern browsers so you can use it's functions right away.
More information and useful links can also be found here:
https://stackoverflow.com/questions/3084675/internationalization-in-javascript