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
Post a Comment