schalkneethling@programming.dev to Web Development@programming.dev · 8 months agoNumber and Currency Formatting in JavaScript using Intl.NumberFormatdev.toexternal-linkmessage-square5fedilinkarrow-up112arrow-down11
arrow-up111arrow-down1external-linkNumber and Currency Formatting in JavaScript using Intl.NumberFormatdev.toschalkneethling@programming.dev to Web Development@programming.dev · 8 months agomessage-square5fedilink
minus-squaretowerful@programming.devlinkfedilinkarrow-up6·8 months agoIts worth creating an Intl formatter outside of a loop, then applying it inside the loop - if you are formatting everything in the loop the same. const formatter = Intl.NumberFormat(/* options */); return items.map(item => { return { ...item, total: formatter.format(item.total) } }); …Or however you choose to mutate an array. Well, certainly it used to be. Not sure if that is still the case!
Its worth creating an Intl formatter outside of a loop, then applying it inside the loop - if you are formatting everything in the loop the same.
const formatter = Intl.NumberFormat(/* options */); return items.map(item => { return { ...item, total: formatter.format(item.total) } });
…Or however you choose to mutate an array.
Well, certainly it used to be. Not sure if that is still the case!
100% Agree