Skip to content

Instantly share code, notes, and snippets.

@veganben
Created February 27, 2015 08:45
Show Gist options
  • Save veganben/a909f42a469302afc87c to your computer and use it in GitHub Desktop.
Save veganben/a909f42a469302afc87c to your computer and use it in GitHub Desktop.
Swiss Number Format
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