wc_add_number_precision()WC 3.2.0

Add precision to a number by moving the decimal point to the right as many places as indicated by wc_get_price_decimals(). Optionally the result is rounded so that the total number of digits equals wc_get_rounding_precision() plus one.

Хуков нет.

Возвращает

int|float.

Использование

wc_add_number_precision( ?float $value, $round );
?float $value (обязательный)
-
$round(true|false)
If the result should be rounded.
По умолчанию: true

Список изменений

С версии 3.2.0 Введена.

Код wc_add_number_precision() WC 8.7.0

function wc_add_number_precision( ?float $value, bool $round = true ) {
	if ( ! $value ) {
		return 0.0;
	}

	$cent_precision = pow( 10, wc_get_price_decimals() );
	$value          = $value * $cent_precision;
	return $round ? NumberUtil::round( $value, wc_get_rounding_precision() - wc_get_price_decimals() ) : $value;
}