wp_fuzzy_number_match() WordPress Function

The wp_fuzzy_number_match() function is used to match a given number against a set of fuzzy numbers. A fuzzy number is a number with a certain range of uncertainty. This function is useful for matching numbers that may not be exact, such as when trying to match a user-entered number to a set of numbers in a database.

wp_fuzzy_number_match( int|float $expected, int|float $actual, int|float $precision = 1 ) #

Checks if two numbers are nearly the same.


Description

This is similar to using round() but the precision is more fine-grained.


Top ↑

Parameters

$expected

(int|float)(Required)The expected value.

$actual

(int|float)(Required)The actual number.

$precision

(int|float)(Optional)The allowed variation.

Default value: 1


Top ↑

Return

(bool) Whether the numbers match within the specified precision.


Top ↑

Source

File: wp-includes/functions.php

function wp_fuzzy_number_match( $expected, $actual, $precision = 1 ) {
	return abs( (float) $expected - (float) $actual ) <= $precision;
}


Top ↑

Changelog

Changelog
VersionDescription
5.3.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.

Show More
Show More