Created
February 27, 2015 08:45
-
-
Save veganben/a909f42a469302afc87c to your computer and use it in GitHub Desktop.
Swiss Number Format
This file contains hidden or 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
| var swissNumberFormattter = function(s) { | |
| var numDec, | |
| decimals, | |
| returnVal; | |
| if(s < 10000) { | |
| returnVal = s; | |
| } else { | |
| if(Math.floor(s) === s) { | |
| numDec = 0; | |
| } else { | |
| numDec = s.toString().split(".")[1].length; | |
| } | |
| decimals = (s - Math.floor(s)).toFixed(numDec); | |
| returnVal = (Math.floor(s) / 1000).toFixed(3).toString().replace(".","'"); | |
| if(numDec) { | |
| returnVal = returnVal + "." + decimals.split(".")[1]; | |
| } | |
| } | |
| return returnVal; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment