Add decimal markers to any integer.
-
-
Save atk/4563237 to your computer and use it in GitHub Desktop.
Decimal Points (for integer numbers)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function( | |
a, // positive integer number | |
b, // counter | |
c // result (array) | |
){ | |
for( | |
a += c = [], // coerce a to string, intialize result array | |
b = a.length; // fill counter with length | |
(b -= 3) > -3; // decrease counter by 3 and check if > -3 | |
c.unshift(a.substr(b < 0 ? 0 : b, b < 0 ? -b : 3)) // fetch the next 3 (or less) numbers | |
); | |
return '' + c // string coercion will automatically add commas (as c.join(',') would) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function(a,b,c){for(a+=c=[],b=a.length;(b-=3)>-3;c.unshift(a.substr(b<0?0:b,b<0?-b:3)));return''+c} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE | |
Version 2, December 2004 | |
Copyright (C) 2011 Alex Kloss <[email protected]> | |
Everyone is permitted to copy and distribute verbatim or modified | |
copies of this license document, and changing it is allowed as long | |
as the name is changed. | |
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE | |
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION | |
0. You just DO WHAT THE FUCK YOU WANT TO. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "theNameOfYourLibWhichMustBeAValidCamelCasedJavaScriptIdentifier", | |
"description": "This should be a short description of your entry.", | |
"keywords": [ | |
"five", | |
"descriptive", | |
"keywords", | |
"or", | |
"fewer" | |
] | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<title>Decimal markers</title> | |
<div>Expected value: <b>12,234,567,890</b></div> | |
<div>Actual value: <b id="ret"></b></div> | |
<script> | |
document.getElementById( "ret" ).innerHTML = (function(a,b,c){for(a+=c=[],b=a.length;(b-=3)>-3;c.unshift(a.substr(b<0?0:b,b<0?-b:3)));return''+c})(1234567890) | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
And not to mention I get no notifications when someone's replying (plus my old notifications gone).