Please login or register. Welcome to the Studio, guest!


Quick Links:


newBookmarkLockedFalling

Aaron

Aaron Avatar
Bad Wolf

****
Dedicated Studio Member

859


November 2006
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

Michael

Michael Avatar
*Has a custom title*



1,462


October 2007
*insert some comments from before PB failed about this code*

:P

Aaron

Aaron Avatar
Bad Wolf

****
Dedicated Studio Member

859


November 2006
*inserts some comments about wanting to do this without loops and using a single replace() at some point*

Michael

Michael Avatar
*Has a custom title*



1,462


October 2007
*mentions something about copying the number_format() php function ... Stolen from Chris* ;D

Chris

Chris Avatar

******
Head Coder

19,519


June 2005
*stabs wrighty for stealing stuff*

Michael

Michael Avatar
*Has a custom title*



1,462


October 2007
Chris Avatar
*stabs wrighty for stealing stuff*


*dies*

Andrew McGivery

Andrew McGivery Avatar
Formerly Fredy

******
Legendary Studio Member

Male
5,742


September 2005
*lulz*
k

Aaron

Aaron Avatar
Bad Wolf

****
Dedicated Studio Member

859


November 2006
Swapped to number_format().

newBookmarkLockedFalling