| Server IP : 46.105.57.169 / Your IP : 216.73.216.67 Web Server : Apache System : Linux webm002.cluster120.gra.hosting.ovh.net 6.18.42-ovh-vps-grsec-zfs+ #1 SMP PREEMPT_DYNAMIC Wed Aug 5 15:59:48 CEST 2026 x86_64 User : verseaumee ( 152031) PHP Version : 8.5.7 Disable Function : _dyuweyrj4,_dyuweyrj4r,dl MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : OFF | Pkexec : OFF Directory : /home/verseaumee/lauvia/wp-content/plugins/woo-stripe-payment/src/Utilities/ |
Upload File : |
<?php
namespace PaymentPlugins\Stripe\Utilities;
class NumberUtil {
/**
* @param $val
* @param int $precision
*
* @return string
*/
public static function round( $val, $precision = 2 ) {
static $decimals;
if ( $decimals === null ) {
$decimals = wc_get_price_decimals();
}
// always use the lower precision number since 2 is the max.
return wc_format_decimal( $val, $precision > $decimals ? $decimals : $precision );
}
/**
* @param float $value
* @param string $currency
* @param int $decimals
*
* @return string
*/
public static function round_incl_currency( $value, $currency, $decimals = 2 ) {
$decimals = isset( Currency::get_currency_decimals()[ $currency ] )
? Currency::get_currency_decimals()[ $currency ] : $decimals;
return NumberUtil::round( $value, $decimals );
}
public static function add_precision( $value, $currency ) {
if ( ! is_numeric( $value ) ) {
$value = 0;
}
// Round to WooCommerce price decimals first
$decimals = wc_get_price_decimals();
$value = floatval( $value );
// Get currency, default to WooCommerce currency if empty
$currency = empty( $currency ) ? get_woocommerce_currency() : $currency;
// Get the currency decimals/exponent from the Currency class
$currencies = Currency::get_currency_decimals();
$exp = isset( $currencies[ $currency ] ) ? $currencies[ $currency ] : 2;
// Multiply by precision to convert to cents/smallest unit
$value = $value * pow( 10, $exp );
// Round to remove any floating point precision issues
$value = round( $value, 0, PHP_ROUND_HALF_UP );
return $value;
}
}