Created
September 6, 2018 17:56
-
-
Save joemaffei/c0db2a84c7365579702393037ff627b3 to your computer and use it in GitHub Desktop.
Converts a number into dollars the "hard" way, because toLocaleString is unsupported by react-native on Android
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
const formatDollarAmount = (num) => ( | |
'$' + `${Math.floor(num)}` | |
.split('') | |
.reverse() | |
.reduce((result, char, index) => { | |
index > 0 && !(index % 3) && result.push(','); | |
return [...result, char] | |
}, []) | |
.reverse() | |
.join('') + `${(num % 1).toFixed(2)}`.substr(1) | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment