php - Separator numbers in jQuery -


this question has answer here:

in php can:

$number = 1234.56; $nombre_format_francais = number_format($number, 2, '.', ' '); 

and shows me:

1 234.56 

how can make in jquery? add separator.

i did searching, come there no built in method:

create number

var num = 1234.56; 

format decimal places - necessary longer decimals...

var result = num.tofixed(2);  

add spaces

result = numberwithspace(result);  function numberwithspace(x) {     return x.tostring().replace(/\b(?=(\d{3})+(?!\d))/g, " "); } 

working fiddle

see this answer original function


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -