Support the ongoing development of Laravel.io →
Article Hero Image

Formatting Monetary Values in JavaScript

10 Jun, 2025 3 min read

Photo by Alexander Grey on Unsplash

Introduction

When building your web applications, you might need to format numbers as monetary values. For example, rather than displaying the value 123.45, you might want to display it as £123.45.

In this Quickfire article, we're going to look at two different approaches to formatting monetary values in JavaScript.

Formatting Single Monetary Values Using "toLocaleString()"

The first approach you can use to format monetary values in JavaScript is the toLocaleString() method. This method formats a number according to the locale and options you specify.

Let's take a look at an example:

const value = 123.45;

const formattedValue = value.toLocaleString('en-GB', {
  style: 'currency',
  currency: 'GBP',
});

// formattedValue will be '£123.45'

In the example above, we've used the toLocaleString() method to format the value as a monetary value in British pound sterling (GBP).

The first argument (en-GB) specifies the locale, which determines how the number is formatted. The second argument provides some options for formatting, such as the style (currency) and the currency code (GBP).

Let's say we wanted to use the fr-FR locale to format the same value in Euros (EUR). We could do the following:

const value = 123.45;

const formattedValue = value.toLocaleString('fr-FR', {
  style: 'currency',
  currency: 'EUR',
});

// formattedValue will be '123,45 €'

Customising the Precision

You may also want to customise the precision of the formatted values. For example, you may want to display the value without any decimal places. You can do this by using the minimumFractionDigits and maximumFractionDigits options.

For example, let's specify that the minimum number of decimal places that can be displayed is 0, and the maximum is 2:

const value = 123.456;

const formattedValue = value.toLocaleString('en-GB', {
  style: 'currency',
  currency: 'GBP',
  minimumFractionDigits: 0,
  maximumFractionDigits: 2,
});

// formattedValue will be '£123.46'

const wholeValue = 123;

const formattedWholeValue = wholeValue.toLocaleString('en-GB', {
  style: 'currency',
  currency: 'GBP',
  minimumFractionDigits: 0,
  maximumFractionDigits: 2,
});

// formattedWholeValue will be '£123'

Formatting Multiple Monetary Values Using "Intl.NumberFormat"

Although it's simple to format a single monetary value using toLocaleString(), if you need to format multiple values, you might want to consider using Intl.NumberFormat. This allows you to create a reusable formatter that can be used to format multiple values.

For example, let's say we want to format multiple values in British Pounds Sterling (GBP):

// Create the formatter that can be reused
const formatter = new Intl.NumberFormat('en-GB', {
  style: 'currency',
  currency: 'GBP',
});

const formattedValueOne = formatter.format(123.45); // '£123.45'
const formattedValueTwo = formatter.format(67.89); // '£67.89'
const formattedValueThree = formatter.format(1000); // '£1,000.00'

As you can see in the example above, we can create a single, reusable formatter using Intl.NumberFormat and then pass each value we want to format to the format method.

Customising the Precision

Similar to the .toLocaleString() method, you can also customise the precision of the formatted values using Intl.NumberFormat. You can specify the minimumFractionDigits and maximumFractionDigits options when creating the formatter:

const formatter = new Intl.NumberFormat('en-GB', {
  style: 'currency',
  currency: 'GBP',
  minimumFractionDigits: 0,
  maximumFractionDigits: 2,
});

const formattedValueOne = formatter.format(123.456); // '£123.46'
const formattedValueTwo = formatter.format(67); // '£67'
const formattedValueThree = formatter.format(1000); // '£1,000'

Conclusion

In this Quickfire article, we've looked at how you can format monetary values in JavaScript using the toLocaleString() method and the Intl.NumberFormat object. Hopefully, this will help you in future projects where you need to display monetary values in a user-friendly way.

If you enjoyed reading this post, you might be interested in checking out my 220+ page ebook "Battle Ready Laravel" which covers similar topics in more depth.

Or, you might want to check out my other 440+ page ebook "Consuming APIs in Laravel" which teaches you how to use Laravel to consume APIs from other services.

If you're interested in getting updated each time I publish a new post, feel free to sign up for my newsletter.

Keep on building awesome stuff! 🚀

Last updated 1 week ago.

driesvints liked this article

1
Like this article? Let the author know and give them a clap!
ash-jc-allen (Ash Allen) I'm a freelance Laravel web developer from Preston, UK. I maintain the Ash Allen Design blog and get to work on loads of cool and exciting projects 🚀

Other articles you might like

Article Hero Image June 22nd 2025

Pass a Query Builder to "whereIn" to Reduce Your DB Queries

Introduction I recently learnt about a cool feature in Laravel that allows you to pass a query build...

Read article
Article Hero Image February 27th 2024

Running custom Artisan commands with Supervisor

If you ever used Laravel queues on the server, you probably came across a section in the <a title...

Read article
Article Hero Image June 14th 2025

Asymmetric Property Visibility in PHP

Introduction Asymmetric visibility is a feature that was introduced in PHP 8.4 (released: November 2...

Read article

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.