Over a million developers have joined DZone.

Currency Formatted String To Number

·
Makes a currency-formatted string numeric

function currency2float(m){
    var pattern  = /[\.,][-|–]?$/;           /* 100.-- >>> 100 */
                                             /* 100,-  >>> 100 */
    var m = m.replace(pattern, "");
    
    var pattern  = /[\.,]([\d]{0,2})$/;      /* 100,95 >>> 100X95 */
    var m = m.replace(pattern, "X$1");
    
    var pattern  = /[\.',]/g;                /* delete ' , .  */
    var m = m.replace(pattern, "");
        
    var m = m.replace(/X/g, '.');            /* 100X95 >> 100.95 */
    
    if(isNaN(m*1)) return false;
    return(m*1);
}
Topics:

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}