How to convert a currency string to a double with jQuery or Javascript?

后端 未结 19 2683
天涯浪人
天涯浪人 2020-11-22 17:30

I have a text box that will have a currency string in it that I then need to convert that string to a double to perform some operations on it.

\"$1,1

19条回答
  •  独厮守ぢ
    2020-11-22 17:57

    For anyone looking for a solution in 2020 you can use Currency.js.

    After much research this was the most reliable method I found for production, I didn't have any issues so far. In addition it's very active on Github.

    currency(123);      // 123.00
    currency(1.23);     // 1.23
    currency("1.23")    // 1.23
    currency("$12.30")  // 12.30
    
    var value = currency("123.45");
    currency(value);    // 123.45
    

提交回复
热议问题