Created
October 2, 2016 18:31
-
-
Save Komock/119f8ee262c38e419f79af6544b1c900 to your computer and use it in GitHub Desktop.
Format Integer to Price with Space (usefull for rubles)
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
// Price Format | |
function formatNum(num){ | |
var num = num + '', | |
arr = num.split(''), | |
arrCopy = arr.slice(0), | |
j = 0; | |
for(var i = arr.length -1 ; i >= 0; i--){ | |
if ( j % 3 === 0 && j !== 0 ) { | |
arrCopy.splice( i + 1, 0, ' ' ); | |
} | |
j++; | |
}; | |
return arrCopy.join(''); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment