DEV Community

SEO - NT Tech Innovation
SEO - NT Tech Innovation

Posted on

Formatting Philippine Peso Prices Correctly in JavaScript (With Intl.NumberFormat)

I was building a small pricing table for a Philippine client last week. Prices per 1,000 units, shown in pesos. Simple, right?

Then the bugs showed up. ₱1000 instead of ₱1,000.00. Tiny values like 0.13 rounding to ₱0. And one browser showing PHP 1,000.00 instead of the peso sign.

Here's what actually works.

The basic formatter

const php = new Intl.NumberFormat('en-PH', {
  style: 'currency',
  currency: 'PHP',
});

php.format(1000);   // "₱1,000.00"
php.format(117);    // "₱117.00"
Enter fullscreen mode Exit fullscreen mode

Using the en-PH locale gives you the peso sign and Filipino-style grouping. Don't hardcode "₱" + value. It breaks on negative numbers and decimals.

Handling very small prices

Some services cost fractions of a peso per unit. Default currency formatting rounds to 2 decimals, which can turn 0.0013 into ₱0.00. Not great on a price list.

const phpPrecise = new Intl.NumberFormat('en-PH', {
  style: 'currency',
  currency: 'PHP',
  minimumFractionDigits: 2,
  maximumFractionDigits: 4,
});

phpPrecise.format(0.13);    // "₱0.13"
phpPrecise.format(0.0013);  // "₱0.0013"
Enter fullscreen mode Exit fullscreen mode

"Per 1,000" pricing without float bugs

Floating point math loves to bite here. 0.1 * 3 is not 0.3 in JavaScript. For money, store values in centavos as integers.

// price per 1,000 stored in centavos
const pricePerThousandCentavos = 11700; // ₱117.00

function totalFor(qty) {
  const centavos = Math.round((pricePerThousandCentavos * qty) / 1000);
  return php.format(centavos / 100);
}

totalFor(2500); // "₱292.50"
Enter fullscreen mode Exit fullscreen mode

Why the "PHP" fallback appears

Older Android WebViews sometimes lack full locale data. They fall back to the ISO code. If that matters, add currencyDisplay: 'narrowSymbol' and test on a real low-end device.

A real-world reference

If you want to see what a clean peso-per-1,000 price list looks like in production, the services page at BoostingPH is a decent example of the format Filipino users expect: peso sign, clear per-1,000 units, no hidden math.

Recap

  • Use Intl.NumberFormat('en-PH', { currency: 'PHP' }).
  • Raise maximumFractionDigits for tiny unit prices.
  • Do money math in centavos.
  • Test on cheap phones. That's where most of your users are.

Written by MD Fozla Rabbi, SEO Specialist.

Top comments (0)