JavaScript Localization Tips

// 512145.14
var num = 512145.14;

Number
var numFormat = new Intl.NumberFormat(‘ru-RU’);
var out = numFormat.format(); // “512 145,14”

Percentage
out = new Intl.NumberFormat(“en-UK”, {
style: “percent”
}).format(0.55); // “55%”

Currency
out = new Intl.NumberFormat(“en-UK”, {
style: “currency”,
currency: “GBP”
}).format(1244.42) // “£1,244.42”

Units – Speed
out = new Intl.NumberFormat(“en-UK”, {
style: “unit”,
unit: “kilometer-per-hour”
}).format(50) // “50 km/h”

Units – Litres
out = new Intl.NumberFormat(“ru-RU”, {
style: “unit”,
unit: “liter”,
unitDisplay: “long”
}).format(5) // “5 литров”

// info at https://www.youtube.com/watch?v=OcsbNgTn-eQ

Was this article helpful?

Related Articles

Leave A Comment?