wc_add_number_precision( float $value, bool $round = true )

Add precision to a number and return a number.


Description Description


Parameters Parameters

$value

(Required) Number to add precision to.

$round

(Optional) If should round after adding precision.

Default value: true


Top ↑

Return Return

(int|float)


Top ↑

Source Source

File: includes/wc-core-functions.php

function wc_add_number_precision( $value, $round = true ) {
	$cent_precision = pow( 10, wc_get_price_decimals() );
	$value          = $value * $cent_precision;
	return $round ? round( $value, wc_get_rounding_precision() - wc_get_price_decimals() ) : $value;
}

Top ↑

Changelog Changelog

Changelog
Version Description
3.2.0 Introduced.


Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.