javascript - Converting a number in English to its digital value (ignore decimals) -


i want convert these types of values, '3 million', '24 thousand', '350 thousand', etc. number. in either javascript(so can client side) or php(server side). there function this? phps strtotime() function?

input                  output 3 million              3000000 24 thousand            24000 350 thousand           350000 

do want combine them well?

function convert(num) {    return num.match(/(\d+)( ?\w* ?)/g).map(mapgroups)     .reduce(function(p,c){return p+c;});    function mapgroups(str){     if (/million/.test(str)){       return str.match(/\d+/)[0] * 1000000;     }                                                                                                                                                                                                            if (/thousand/.test(str)){       return str.match(/\d+/)[0] * 1000;     }        if (/hundred/.test(str)){       return str.match(/\d+/)[0] * 100;     }        return +str;   } }  convert("3 million 240 thousand 7 hundred 54"); //3240754 convert("5 millions 7 hundreds 54"); //5000754 

it basic grip.


Comments

Popular posts from this blog

javascript - Karma not able to start PhantomJS on Windows - Error: spawn UNKNOWN -

Nuget pack csproj using nuspec -

c# - Display ASPX Popup control in RowDeleteing Event (ASPX Gridview) -