|
Syntax: number_format( number, dec, float sep, thousands sep) function number_format(a, b, c, d) { return (a = (a + "").split("."))[0].replace(/\d(?=(.{3})+$)/g, "$&" + (d || ",")) + ((c || ".") + (a[1] || "") + Array(b = b || 0).join(0)).substr(0, b && b + 1); }Edit: Added useless dec parameter and replaced prototype with plain ol' function. Edit: Informed that when dec is 0 on a floating number, the decimal isn't removed. Fixededed. Edit: Updated to add 0s when dec is extended. Also had the thousands and float sep parameters swapped. Edit: Optimized a bit. =)
Last Edit: Aug 25, 2010 4:41:20 GMT by Aaron
|
|
|
|
*insert some comments from before PB failed about this code*
|
|
|
|
*inserts some comments about wanting to do this without loops and using a single replace() at some point*
|
|
|
|
*mentions something about copying the number_format() php function ... Stolen from Chris*
|
|
|
|
*stabs wrighty for stealing stuff*
|
|
|
|
|
*stabs wrighty for stealing stuff* *dies*
|
|
|
|
|
Swapped to number_format().
|
|
|