Skip to content

Instantly share code, notes, and snippets.

@slWsu
Last active August 29, 2015 14:23
Show Gist options
  • Save slWsu/e3acada55bf9605e5928 to your computer and use it in GitHub Desktop.
Save slWsu/e3acada55bf9605e5928 to your computer and use it in GitHub Desktop.
Formater les grands nombre pour les rendre lisibles
/**
* 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