how do you format a number to currency when using React native EXPO?

前端 未结 5 1572
深忆病人
深忆病人 2020-12-16 10:45

how do I take a number like 10000 and have it output as $10,000.00?

I even had a problem with String.format(...) with a

5条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-16 10:49

    could be achieved as shown below, and you could also remove trailing 00 at the end if there is no decimals

          costing= () => {
            const cost= 1478.90 + 940;
            return parseFloat(cost).toFixed(2).replace(/(\d)(?=(\d{3})+(?!\d))/g, '$1,');
          }
    

提交回复
热议问题