PDA

View Full Version : PHP Help. Returning a value to 2 decimal places.



YouFail
20-12-2006, 05:30 PM
Ok.

Im coding a script and after you order it adds on 17.5% VAT. But this causes problems and gives out a number. Something like $29.36325 when it should be $29.36



$vat = 24.99 / 100 * 17.5;

$gt = $vat + 24.99;

echo ("You ordered $_POST[iname]. The price is $24.99 (excluding VAT). The grand total is $$gt ");


Thats the code im using. If anybody could help me it'd be great. I tried a few codes but nothing so far has worked.

:Blob
20-12-2006, 06:17 PM
Display it as a image for some reason then add into it imagechar so it limits the text to about 20 so it misses out the other bits.

Heinous
21-12-2006, 04:25 AM
round();

...

Blinger1
21-12-2006, 08:26 AM
it should end up like:


$vat = 24.99 / 100 * 17.5;

$gt = $vat + 24.99;

echo ("You ordered $_POST[iname]. The price is $24.99 (excluding VAT). The grand total is $");
echo round ($gt, 2);

YouFail
21-12-2006, 03:37 PM
Thanks all. I tried the round function but it didn't work. If anyone needs this use the money_format() function.

Want to hide these adverts? Register an account for free!