How to format numbers as currency strings (2024)

The ProblemJump To Solution

You want to format a number as a currency string to display to a user. How do you do this?

The Solution

You can create an Intl.NumberFormat object to format a number as a currency string. To create the object, call the Intl.NumberFormat() constructor. This object allows for language-sensitive number formatting.

The Intl.NumberFormat() constructor has two optional arguments: locales and options. The locales argument is a language tag string or an array of language tag strings. If you don’t pass in a locales string, the browser detects the preferred language of the user. The options object has multiple properties that can be set. For creating a currency string, set the formatting style property to “currency” and set the currency property to the ISO 4217 currency code for the currency. You can find a list of the currency codes here.

Here’s an example of how to format a number as a currency string:

Click to Copy

const { format } = new Intl.NumberFormat('en-US', { style: 'currency', currency: 'USD',});console.log(format(101.04)); // $101.04console.log(format(99.99)); // $99.99

You can also set the currencyDisplay property of the options object to change how the currency is displayed. The default value is “symbol” but if you change it to “name”, the localized currency name is displayed. You can also control the number of decimal places by using the maximumFractionDigits property:

Click to Copy

const { format } = new Intl.NumberFormat('en-US', { style: 'currency', currency: 'USD', maximumFractionDigits: 1, currencyDisplay: 'name',});console.log(format(101.04)); // 101.0 US dollarsconsole.log(format(99.99)); // 100.0 US dollars

If you need to round the fractional digits of the currency to the nearest fractional increment, for example 0.1, you can use the roundingIncrement property:

Click to Copy

const { format } = new Intl.NumberFormat('en-Za', { style: 'currency', currency: 'ZAR', maximumFractionDigits: 2, roundingIncrement: 10,});console.log(format(84.34)); // R 84,30console.log(format(22.35)); // R 22,40

How to format numbers as currency strings (2024)
Top Articles
Emerging Risk: Corporate Social Responsibility and ESG - M3 Insurance
Most Popular Crypto in Nigeria
Design215 Word Pattern Finder
Compare Foods Wilson Nc
Urist Mcenforcer
Fat People Falling Gif
Blackstone Launchpad Ucf
Puretalkusa.com/Amac
Student Rating Of Teaching Umn
Declan Mining Co Coupon
Camstreams Download
Jscc Jweb
Gfs Rivergate
Charmeck Arrest Inquiry
Connect U Of M Dearborn
Daily Voice Tarrytown
Sam's Club La Habra Gas Prices
Gdlauncher Downloading Game Files Loop
Google Flights Missoula
Convert 2024.33 Usd
Www Craigslist Milwaukee Wi
Wausau Marketplace
Foxy Brown 2025
Lakers Game Summary
Yog-Sothoth
Seeking Arrangements Boston
Engineering Beauties Chapter 1
1145 Barnett Drive
Harbor Freight Tax Exempt Portal
Busted Mugshots Paducah Ky
As families searched, a Texas medical school cut up their loved ones
Funky Town Gore Cartel Video
Proto Ultima Exoplating
Pnc Bank Routing Number Cincinnati
How to Draw a Bubble Letter M in 5 Easy Steps
Solve 100000div3= | Microsoft Math Solver
Gideon Nicole Riddley Read Online Free
Weekly Math Review Q4 3
Edict Of Force Poe
Telegram update adds quote formatting and new linking options
How much does Painttool SAI costs?
Kerry Cassidy Portal
Topos De Bolos Engraçados
Electronic Music Duo Daft Punk Announces Split After Nearly 3 Decades
Mid America Irish Dance Voy
Join MileSplit to get access to the latest news, films, and events!
Rs3 Nature Spirit Quick Guide
Expendables 4 Showtimes Near Malco Tupelo Commons Cinema Grill
Love Words Starting with P (With Definition)
6463896344
Publix Store 840
WHAT WE CAN DO | Arizona Tile
Latest Posts
Article information

Author: Kerri Lueilwitz

Last Updated:

Views: 5821

Rating: 4.7 / 5 (67 voted)

Reviews: 90% of readers found this page helpful

Author information

Name: Kerri Lueilwitz

Birthday: 1992-10-31

Address: Suite 878 3699 Chantelle Roads, Colebury, NC 68599

Phone: +6111989609516

Job: Chief Farming Manager

Hobby: Mycology, Stone skipping, Dowsing, Whittling, Taxidermy, Sand art, Roller skating

Introduction: My name is Kerri Lueilwitz, I am a courageous, gentle, quaint, thankful, outstanding, brave, vast person who loves writing and wants to share my knowledge and understanding with you.