How to add percentage to a PHP value?

Asked

Viewed 665 times

-2

I’m trying to add a percentage of the value to itself, but I couldn’t do.

   <?php

   $data = json_decode(file_get_contents("https://broker.negociecoins.com.br/api/v3/btcbrl/ticker"));
  echo "<pre>";
  print_r($data->sell);
  echo "</pre>"; ?>

I have this JSON that returns me a value and I would like to add for example +30% in this value before displaying it, but in any way that I tried it does not work, someone has an idea?

2 answers

1


You can do it like this:

$valor *= (1+$percentual/100);

$data->sell *= (1+30/100); //30% de acréscimo

Or so.

$valor_acrescido = (($data->sell*30)/100)+$data->sell;

-1

Percentage

$valor_acrescido = (($data->sell*30)/100)+$data->sell;
  • What is the difference of your answer to the other?

Browser other questions tagged

You are not signed in. Login or sign up in order to post.