문제

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