Menu

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

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

DEV Community: beginners·SEO - NT Tech Innovation·about 19 hours ago
#WQa0Rp0E
#devtobeginners#devto#dev#currency#format
Reading 0:00
15s threshold

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 .…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.