Hello. I make the algorithm of the exchange, which determines the required amount and the coefficient of 2 players based on the amount and coefficient of 1 player.

class Bet{ //Поиск коэффициента 2 игрока public function findCoefficient($other_coefficient){ return round($other_coefficient / ($other_coefficient - 1),2); } //Определяет прибыль 1 игрока - что также является нужной, стартовой суммой 2 игрока public function findProfit($money, $coefficient){ return round($money * $coefficient-$money, 2); } //Вывод игрока public function findOutcome($money, $coefficient){ return round($money * $coefficient,2); } } 

The task is to provide data with a maximum of 2 characters after the point (2.30). But using round (num, 2). All calculations go astray.

 $money1P = 7433; $cof1P = 1.15; $cof2Player = $bet->findCoefficient($cof1P); $money2Player = $bet->findProfit($money1P, $cof1P); $bet->findOutcome($money1P, $cof1P); // 8547.95 $bet->findOutcome($money2Player, $cof2Player); //8551.67 

    1 answer 1

    Round off values ​​only when you need to display them.

    Rounding at each operation, you kill the accuracy of calculations.