<div id="price" data-price="1654789"></div>
function formatPrix(str) {
let num = parseInt(str) / 1000;
return new Intl.NumberFormat('fr-BE', {
minimumFractionDigits: 3,
maximumFractionDigits: 3
}).format(num);
}
const price = document.getElementById("price");
var priceNumber = price.getAttribute("data-price");
let prixFormate = formatPrix(priceNumber);
document.getElementById("price").textContent = prixFormate
function formatPrix($str) {
// Convertir la chaîne en entier et diviser par 1000
$num = intval($str) / 1000;
// Formater le nombre avec 3 décimales et un séparateur de milliers
return number_format($num, 3, '.', '');
}
// Exemple d'utilisation
$prixFormate = formatPrix("40000");
echo $prixFormate; // Affiche "40.000"