public static function margin($cost, $charge_out, $round = false)
    {
        // Avoid division by zero
        if ($cost == $charge_out) {
            return (float)0;
        }

        $cost        = self::mul($cost, -1); // make cost be a negative.
        $numerator   = self::add($cost, $charge_out);
        $denominator = max(abs($cost), abs($charge_out));
        $result      = self::div($numerator, $denominator);
        $product     = self::mul($result, 100);
        $margin      = $round ? self::round($product) : $product;

        return (float)$margin;
    }