How to add commas in big numbers

I want to have the calculated number use commas. So instead of $1000, I want $1,000 etc. How do I go about doing this in my codepen? Thanks. https://codepen.io/creativecodepenuser/pen/JjbVQxY

Article about currency formatting in JS.

1 Like

@MyTrueName I added yearlyFunnyMoney.toLocaleString('en-US', { style: 'currency', currency: 'USD' }) as your article suggested but it doesn’t really do anything.

When I run the above code when yearlyFunnyMoney is assigned the value 1000 it produces $1,000.00

1 Like

@RandellDawson Interesting. Thanks for sharing. Why is this result not produced in my codepen?

Because you must assign the value returned from the toLocaleString method to a variable. yearlyFunnyMoney does not change unless you assign a different value to it.

You could do that by:

yearlyFunnyMoney = yearlyFunnyMoney.toLocaleString('en-US', { style: 'currency', currency: 'USD' })
1 Like

If you do not want to have the cents at the end, you can add maximumFractionDigits: 0 to the options object.

1 Like