wc_legacy_round_half_down( float $value, int $precision )

Round half down in PHP 5.2.


Description Description


Parameters Parameters

$value

(Required) Value to round.

$precision

(Required) Precision to round down to.


Top ↑

Return Return

(float)


Top ↑

Source Source

File: includes/wc-formatting-functions.php

function wc_legacy_round_half_down( $value, $precision ) {
	$value = wc_float_to_string( $value );

	if ( false !== strstr( $value, '.' ) ) {
		$value = explode( '.', $value );

		if ( strlen( $value[1] ) > $precision && substr( $value[1], -1 ) === '5' ) {
			$value[1] = substr( $value[1], 0, -1 ) . '4';
		}

		$value = implode( '.', $value );
	}

	return round( floatval( $value ), $precision );
}

Top ↑

Changelog Changelog

Changelog
Version Description
3.2.6 Introduced.


Top ↑

User Contributed Notes User Contributed Notes

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