Setting up a multilingual site that involves dealing with currencies is my current task. My goal is to accurately display currency formats based on the selected language. Thankfully, handling the server side PHP tasks has been quite easy for me. By utilizing PHP's NumberFormatter and strftime in combination, I have successfully managed to format currencies and dates correctly.
However, there is now a need to implement the same level of formatting on the client side using JavaScript.
During my research, I stumbled upon Globalization (formerly a jQuery plugin) which seems to offer promising solutions.
If I wish to showcase a dollar value in American English, I can achieve it like this:
jQuery.preferCulture("en-US");
// Formatting price
var price = jQuery.format(3899.888, "c");
//Assigning stock price to the control
jQuery("#price").html(price);
Resulting in:
$3,899.89
Similarly, if I execute:
jQuery.preferCulture("fr-FR");
// Formatting price
var price = jQuery.format(3899.888, "c");
//Assigning stock price to the control
jQuery("#price").html(price);
I will see:
3 899,89 €
This output looks perfect, but now I am faced with the challenge of displaying multiple currencies. For instance, if 'fr-FR' is set as my preferred culture, how can I present a dollar value in the following manner:
3 899,89 $
To clarify, the format should be in French style, while the currency symbol remains that of the American Dollar. Despite searching, I have not yet discovered a method to pass a currency symbol as an argument.