Vanilla JavaScript Projects

Project 75, E-commerce and business

Multi-currency Prices

Show every visitor prices in money they understand. The page guesses the right currency, rounds to tidy price points and formats numbers the local way.

$£
Main API
Intl.NumberFormat
Guess
navigator.language
Dependencies
None
Your browser
Checking

Prices around the world

Pick a currency or let the page guess. Switch rounding on and off and compare the formats.

One product price in every currency
CurrencyLocale formatRate from USD

How it works

  1. Guess the currencyIntl.Locale turns the browser language into a region, like en-GB into GB, and a small table maps that to a currency.
  2. Convert, then tidyThe dollar price is multiplied by the rate, then rounded up to a neat price point so a chair costs 229 euros, not 229.08.
  3. Format the local wayIntl.NumberFormat adds the right symbol, separators and decimals. Yen has no decimals and rupees group digits in lakhs.
const region = new Intl.Locale(navigator.language).maximize().region; // "GB"
const currency = { GB: "GBP", DE: "EUR", IN: "INR", BD: "BDT" }[region] || "USD";

const local = price * rates[currency];
new Intl.NumberFormat("en-IN", { style: "currency", currency: "INR" })
  .format(124500);                     // "₹1,24,500.00"