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.

No Hooks.

Return

Int|float.

Usage

wc_add_number_precision( ?float $value, $round );
?float $value (required)
-
$round(true|false)
If the result should be rounded.
Default: true

Changelog

Since 3.2.0 Introduced.

wc_add_number_precision() code WC 8.9.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;
}