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

15 lines
508 B
JavaScript
Raw Normal View History

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