0. */ final class MarginRatio { /** * @param MoneyAmount|null $gross_profit Gross profit. * @param MoneyAmount|null $revenue Revenue. * @param int $scale Decimal places for ratio string. * @return string|null */ public static function decimal( $gross_profit, $revenue, $scale = 8 ) { if ( ! $gross_profit instanceof MoneyAmount || ! $revenue instanceof MoneyAmount ) { return null; } if ( ! $revenue->is_positive() ) { return null; } Bcmath::require_extension(); return bcdiv( $gross_profit->to_decimal_string(), $revenue->to_decimal_string(), max( 0, min( 8, (int) $scale ) ) ); } }