Created
May 25, 2019 10:16
-
-
Save dmjcomdem/c07aaea34ec199a6199a7e217e4c214e to your computer and use it in GitHub Desktop.
Добавляет нужный префикс к цифре, для порядка до 1 миллиона
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
function formatCurrencyToString(number) { | |
if (!number) return ''; | |
return String(number).replace(/(\d+)(\d{1})\d{2}/g, (value, group1, group2) => { | |
return `${(group2 > 0) ? `${group1}.${group2}` : `${group1}`}k`; | |
}); | |
} | |
formatCurrencyToString(452230) // '452.2k' | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment