Make your app look globally professional. Instantly.
Tailgrids MCP, UI Components for AI Coding Agents
Use Tailgrids components directly in Cursor, Windsurf, and VS Code Copilot. Let your AI agent generate and modify UI for you.
2200+ Free HTML Templates, All in One Place
Find free HTML, Tailwind, React, Next.js and more templates for your next project. All curated, all free, ready to use today.
Hey everyone,
You have a number. You want to format it as currency, or with thousand separators, or in a different language’s format.
Most devs write their own function for this. You don’t have to.
The Code: Intl.NumberFormat
const price = 1234567.89;
new Intl.NumberFormat("en-US", {
style: "currency",
currency: "USD",
}).format(price);
// "$1,234,567.89"
Works with any locale, any currency. No library. No regex. Built right in.
// Euros in German format
new Intl.NumberFormat("de-DE", {
style: "currency",
currency: "EUR",
}).format(price);
// "1.234.567,89 €"
Why this is a win:
- 100% browser support. Works in every major browser and Node.js. No polyfill needed.
- Handles the hard stuff for you. Commas, periods, currency symbols, decimal places. All formatted correctly for the target locale automatically.
- Works for non-currency numbers too. Percentages, compact notation (“1.2M”), units. It does all of it.
new Intl.NumberFormat("en-US", {
notation: "compact",
}).format(1234567);
// "1.2M"
One thing to keep in mind:
Create the formatter once and reuse it – new Intl.NumberFormat() has a small setup cost. If you’re formatting many numbers, store the instance in a variable and call .format() on it repeatedly.
Happy coding!
Marko