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.

@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

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.