如何将货币转换为数字

Based off a simlar question asked here - How to convert a currency string to a double with jQuery or Javascript?, I need to take a currency that can be in the format of

-143,000.00并将其转换为2种情况:

  1. 输出为-143000.00
  2. 输出为-1430000

我对正则表达式一点都不擅长,所以我尝试了一些如下2项的技巧:

  1. I need to remove all of the currency except for the -
const value = "-143,000.00";
Number(value.replace(/[^0-9.,]+/g, ''))

and my second use case is I need to remove all but keep the .

const value = "-143,000.00";
Number(value.replace(/[^0-9.-]+/g, ''));

感谢您提供的帮助。

评论