0
<?php echo (($priceInt[0]-$specialInt[0])/$priceInt[0])*100 ?>

For every price this gives me something like 11,111111111 or 3,3433333333 How can i limit it so i will get only 11 or 3 ? Without anything after " , ".

Marged
  • 10,577
  • 10
  • 57
  • 99

3 Answers3

3

Take a look at http://php.net/manual/fr/function.number-format.php

Use it like this :

echo number_format((($priceInt[0]-$specialInt[0])/$priceInt[0])*100, 0, '', '');

If you just need the integer part just use :

echo intval((($priceInt[0]-$specialInt[0])/$priceInt[0])*100);
Raphaël Vigée
  • 2,048
  • 14
  • 27
0

You can use sprintf() like below:

echo sprintf("%d",'3,3433333333'); //output : 3

or

echo sprintf("%d",'11,111111111'); //output : 11

In your case:

echo sprintf("%d",((($priceInt[0]-$specialInt[0])/$priceInt[0])*100));
Ali MasudianPour
  • 14,329
  • 3
  • 60
  • 62
  • `echo sprintf()` is an "antipattern". There is absolutely no reason that anyone should ever write `echo sprintf()` -- it should be `printf()` without `echo` every time. – mickmackusa Apr 16 '22 at 02:27
0

Thanks a lot guys i fixed it

echo sprintf("%d",((($priceInt-$specialInt)/$priceInt)*100));
  • `echo sprintf()` is an "antipattern". There is absolutely no reason that anyone should ever write `echo sprintf()` -- it should be `printf()` without `echo` every time. – mickmackusa Apr 16 '22 at 02:27