Last active
August 29, 2015 14:23
-
-
Save slWsu/e3acada55bf9605e5928 to your computer and use it in GitHub Desktop.
Formater les grands nombre pour les rendre lisibles
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
/** | |
* Formater les grands nombres pour les rendre lisibles | |
* | |
* @param {int|float} nbr Nombre a formater | |
* @returns {formatageGrandNombre.nombre|String} Le nombre formaté | |
*/ | |
function formatageGrandNombre(nbr) { | |
var retour = '', i, j = 0; | |
for (var i = nbr.length - 1; i >= 0; i--) { | |
if (j !== 0 && j % 3 === 0) | |
retour = nbr[i] + ' ' + retour; | |
else | |
retour = nbr[i] + retour; | |
j++; | |
} | |
return retour; | |
} | |
var nb1 = '432566057'; | |
var nb2 = '4325660453.57'; | |
console.log(formatageGrandNombre(nb1)); | |
console.log(formatageGrandNombre(nb2)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment