-4

I have a amount without 20% Tax in my country.. For example, 12,24 € it s without tax and 14,70 EUR it's with a TAX.

How can I add 20% to 12.24 EUR Amount in PHP?

My script is:

<? echo round($cena*(20/100)+$cena, 2);?>

But with this script is amount with TAX 14,40 EUR and in real it is 14,70 EUR. Where is problem? And numbers with zero at start it don't calulcate.. It will show 0,- EUR.

Thanks.

4 Answers4

2

Use this

 $num = 12.24;
 $percentage = 20;
 $num += $num*($percentage/100);
 $num = round($num, 1);      // 4
 $num = sprintf('%0.2f', $num);
 echo $num;
Ninju
  • 2,522
  • 2
  • 15
  • 21
0

As mentioned in comments, just multiply that number by 1.2. So:

<?php echo round($cena * 1.2, 2); ?>
Martin Heralecký
  • 5,649
  • 3
  • 27
  • 65
0

if you use calculator to solve it, 14.70 is correct. to get 14.40

<?php echo round($cena * 0.18, 2); ?>

0.18 is 18%

Fenny
  • 41
  • 9
0

But with this script is amount with TAX 14,40 EUR and in real it is 14,70 EUR. Where is problem?

The problem is with the format of your input, 12,24. It is treated as 12. This is probably because PHP expects the decimal point to be . and not ,.

Klas Lindbäck
  • 33,105
  • 5
  • 57
  • 82