Created
April 8, 2016 12:09
-
-
Save robert-moore/32149575e79ebf6d742f987e17d9784c to your computer and use it in GitHub Desktop.
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 numberFormat(amount, prefix, suffixArray, maxWholeDigitLength, decimalLength) { | |
var suffixIndex = 0; | |
while(amount > Math.pow(10, maxWholeDigitLength) && suffixIndex < suffixArray.length) { | |
amount /= 1000; | |
suffixIndex++; | |
} | |
return prefix + amount.toFixed(decimalLength) + suffixArray[suffixIndex]; | |
}; | |
var dollarSuffix = ["", "K", "M", "B"]; | |
var dollarPrefix = "$"; | |
numberFormat(1000000, dollarPrefix, dollarSuffix, 2, 1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment