kevinabraham kevinabraham - 4 months ago 6
PHP Question

php function that takes a number and subtracts 1% 3 times

I'm trying to create a php method that will take an int and subtract

1% 3 times
. So for example if we passed in a number like
100
. It would then remove
1% looping 3x
. So something like this:

input = 100

return
-> 97
-> 94.09
-> 91.2673

Answer

What i get from your out put is:-

3% of the first input and then 3% of the new number(comes from the first calculation)and then again 3% of the new number (comes from the second calcultion). So you have to do it like below:-

<?php

$original_input = 100;
$new_one = '';
for($i =1;$i<=3;$i++){
   if($new_one !==''){
     $new_one = $new_one - ($new_one*3/100);
   }else{
     $new_one = $original_input - ($original_input*3/100);
   }
  echo $new_one.'<br/>';
}

Output:- https://eval.in/606403

First what i think is captured here:-

https://eval.in/606402

Comments