This repository has been archived on 2024-10-29. You can view files and clone it, but cannot push or open issues or pull requests.
FunctionProject/api/assets/functions/secondary/formatNumberResult.js

14 lines
517 B
JavaScript
Raw Normal View History

/**
* @description Formate un nombre avec des espaces.
* @param {Number} number
* @param {String} separator Le séparateur utilisé pour la virgule (exemple: "." ou ",")
* @returns {String} - Le nombre formaté
* @examples formatNumberResult(76120) '76 120'
*/
function formatNumberResult(number, separator = ".") {
let parts = number.toString().split(separator);
parts[0] = parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, " ");
return parts.join(separator);
}
module.exports = formatNumberResult;