Вопрос

I am trying to give the money format 2 variables but I am getting an error message which is this post topic

I did it like

$pricetotal = $price * $each_item['quantity'];
$cartTotal = $pricetotal + $cartTotal;
$minicartTotal = $pricetotal + $cartTotal;
setlocale(LC_MONETARY, "en_GB.UTF-8");
$pricetotal = money_format("%n", $pricetotal);

I am getting the error message on this codes

setlocale(LC_MONETARY, "en_GB.UTF-8");
$_SESSION ['minicart'] = $minicartTotal = money_format("%n", $cartTotal);
$cartTotal = money_format("%n", $cartTotal);

also u can see $minicartTotal and $cartTotal are both doing the same thing... but they i have done it is that i gave it a different variable number but the contents is the same.

What is the best way of doing this to stop the errors

Это было полезно?

Решение

The easiest way is just to typecast the number like this:

$_SESSION['minicart'] = $minicartTotal = money_format("%n", (double)$cartTotal);

But the best way is to make sure that $price is a double and $each_item['quantity'] is a integer because they are the only unknown variables in your example and if they aren't those types you will get that error.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top