Вчера всё-таки решил эту задачу. Вот таким способом
Всем большое спасибо за помощь
function fillTank(fuelPrice, amount = this.vehicle.maxTankCapacity - this.vehicle.fuelRemains) {
let totalPrice = amount * fuelPrice;
let totalAmount = amount;
const customerMoney = +this.money.toFixed(1);
const maxAmount = this.vehicle.maxTankCapacity - this.vehicle.fuelRemains;
if(amount >= maxAmount){
totalAmount = maxAmount;
totalPrice = totalAmount * fuelPrice;
}
if(this.money < totalPrice){
totalAmount = customerMoney / fuelPrice;
totalPrice = totalAmount * fuelPrice;
}
if(totalAmount < 2){
totalAmount = 0;
totalPrice = 0;
}
this.money = +(customerMoney - totalPrice).toFixed(1);
this.vehicle.fuelRemains += +totalAmount.toFixed(1);
}