I have $qty and $amount that are both strings. i would like to do $qty * $amount.
I have tried intval($qty) * intval(amount) but i loose the decimal if i do it that way... 4 * 8.29 = 32
1.75 * 2.00 = 3.50 < this is what i want.
thanks.
how to convert string to number for calculations...
Moderator: General Moderators
-
grabber_grabbs
- Forum Commoner
- Posts: 60
- Joined: Mon Oct 10, 2011 6:13 pm
-
grabber_grabbs
- Forum Commoner
- Posts: 60
- Joined: Mon Oct 10, 2011 6:13 pm
Re: how to convert string to number for calculations...
Thanks Celauran again, do you know why this is not working ?
$extvalue = floatval($QUANTITY_0) * floatval($PRICE_0);
$extvalue = sprintf("%8,2", $extvalue);
echo $extvalue
// if qty = 1 and price = 1.50 i still have 1.5 after the springf function applied. I would like to have 1.50 for the result.
// floatval is doing what it should.
$extvalue = floatval($QUANTITY_0) * floatval($PRICE_0);
$extvalue = sprintf("%8,2", $extvalue);
echo $extvalue
// if qty = 1 and price = 1.50 i still have 1.5 after the springf function applied. I would like to have 1.50 for the result.
// floatval is doing what it should.
Re: how to convert string to number for calculations...
Code: Select all
printf("%01.2f", $val);