DEV Community

SEO - NT Tech Innovation
SEO - NT Tech Innovation

Posted on Edited on

Formatting Taka Amounts for Bangladeshi Users in JavaScript (Intl.NumberFormat, Bangla Digits Included)

Bangladeshi users read prices two ways. With Latin digits, like 1,250.50. And with Bangla digits, like ১,২৫০.৫০. Grouping also follows the South Asian lakh pattern for large numbers. The good news is that JavaScript handles all of it natively.

Latin digits, Taka currency

const bdtEn = new Intl.NumberFormat('en-BD', {
  style: 'currency',
  currency: 'BDT',
});

console.log(bdtEn.format(1250.5));
console.log(bdtEn.format(1234567));
Enter fullscreen mode Exit fullscreen mode

Depending on the runtime you'll see BDT or the ৳ sign in the output. Large numbers get lakh grouping, so 1234567 becomes 12,34,567.

Bangla digits

const bdtBn = new Intl.NumberFormat('bn-BD', {
  style: 'currency',
  currency: 'BDT',
});

console.log(bdtBn.format(1250.5)); // Bangla digits with the Taka sign
Enter fullscreen mode Exit fullscreen mode

Let the user choose

Don't guess from the browser language alone. Many Bangladeshi users keep their phone in English but prefer Bangla prices, or the other way around. A small toggle saved in localStorage solves it.

function formatTaka(amount) {
  let pref = 'en';
  try { pref = localStorage.getItem('digits') || 'en'; } catch (e) {}
  return (pref === 'bn' ? bdtBn : bdtEn).format(amount);
}
Enter fullscreen mode Exit fullscreen mode

Per-1000 pricing

SMM panels quote rates per 1000. Calculate in poisha, which is one hundredth of a Taka, and round once.

function costPoisha(ratePer1000, qty) {
  return Math.round((Math.round(ratePer1000 * 100) * qty) / 1000);
}

console.log(formatTaka(costPoisha(45, 2500) / 100)); // 112.50 Taka
Enter fullscreen mode Exit fullscreen mode

A real-world shape to test against

Any public Taka price list works as test data. SMM Booster BD is an SMM panel in Bangladesh, and its services list uses the usual per-1000 layout with minimum and maximum quantities.

Summary

  • Use en-BD or bn-BD with currency BDT.
  • Let users pick digits.
  • Keep money as integers until the last step.

Top comments (0)