How to combine PHP and interest? (New task)

Please help me solve a small problem with percentages+ PHP 🙂

<?php
  $x = 100; //  ""   100
  $y = $x - 10%; //  "Y"  ,   100  10%
  echo $y;    //  
?>

If everything was so easy, then the variable “Y” was assigned the number 90, but it gives an error in the browser 🙁 I understand that I wrote the task incorrectly. Please help and show how to correctly write tasks with percentages in PHP code.

Thanks in advance. AronTito

Complicate the problem Einsteins

<?php
$X = 1536.56;    
$Z = $X - 11.5%;    
echo $Z //    ???
?>

Answer 1, authority 100%

Sort of simple:

<?php
  $x = 100;
  $y = $x * ( 100 - 10 ) / 100; // 100%   10%
  //  100     
  // :
  $y = 0.9 * $x;
  echo $y;
?>

Answer 2, authority 100%

Learn materiel, and not even php, but 5th grade matan

$x = 100; //  ""   100
$y = $x * 0.9; // ,  , $x * (100-10)*0.01  $x - $x*(10)*0.01

Answer 3, authority 50%

A percentage is (by definition) a hundredth. There are no percentages in PHP as such. The %character serves other purposes.

Whenever you work with percentages (subtract as in your case) – work with hundredths (fractions) of numbers.

If you need to subtract 10 percent, it just means that you need to subtract 10 hundredths. 10 times 1/100. The x in your question acts as the original number. And its percentage is a hundredth of it, x/100. 10 percent of x is ten such shares (x/100) * 10.

Thus, an entry like y = x - 10%becomes:

y = x - ((x / 100) * 10)

How many percent you want to subtract (or add or do whatever), enter that much at the end of the expression.


Answer 4

Yes, just everything!

Subtract 10% from 100:

<?php
  $x = 100;
  $y = $x * 0.9;
  echo $y;
?>

Answer = 90

Subtract 11.5% from 1536.56:

<?php
  $x = 1536.56;
  $y = $x * 0.885;
  echo $y;
?>

Answer = 1359.8556


Answer 5

I think it would be useful to take a variable, as a percentage, and calculate it.

<?
    $CAS = 1536.56;// 
    $procent = 11.5;//    .
    echo($CAS-($CAS/100*$procent));
?>