Created
October 22, 2019 08:41
-
-
Save Warrenn/00d0d3fea03cb9ea62982b3511e55c26 to your computer and use it in GitHub Desktop.
show currency
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
showCurrency(value: number, precision: number, seperator: string, decimalSeperator: string): string { | |
const stringValue = `${value || 0}` | |
const parts = stringValue.split('.') | |
let numeric = `${parts[0]}` | |
if (seperator) numeric = numeric.replace(/(\d)(?=(\d{3})+(?!\d))/g, `$1${seperator}`) | |
let decimal = `${parts[1] || 0}` | |
if (precision > 0) decimal = decimal.padEnd(precision, '0') | |
decimalSeperator = decimalSeperator || '.' | |
return `${numeric}${decimalSeperator}${decimal}` | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment