I need to convert result of this function to number:
const [nbChambres, setNbChambres] = useState(1);
const [nbNuits, setNbNuits] = useState(1);
function calculatePrixTotal(){
const nbChambresInt = parseInt(nbChambres) || 1;
const nbNuitsInt = parseInt(nbNuits) || 1;
let priceNumber = price.substring(1);
if(priceNumber.includes(',')) {
priceNumber = parseInt(priceNumber.replace(',', ''));
const prixTotal = String(priceNumber * nbNuitsInt * nbChambresInt);
return prixTotal.slice(0, prixTotal.length - 3) + "," + prixTotal.slice(prixTotal.length - 3);
} else {
return String(parseInt(priceNumber) * nbNuitsInt * nbChambresInt);
}
}
Here is the function I made to make the subtraction, I got NaN as the result:
function calculateNewMoneyBalance(){
const calcInt = parseFloat(calculatePrixTotal);
const moneyInt = parseInt(MoneyBalance);
console.log(typeof moneyInt);
return parseInt(moneyInt - calcInt);
}
Hi add method to function call
let calcInt= parseFloat(calculatePrixTotal())