absint( mixed $maybeint ): int

Convert a value to non-negative integer.


Parameters

$maybeint mixed Required
Data you wish to have converted to a non-negative integer.

Top ↑

Return

int A non-negative integer.


Top ↑

Source

File: wp-includes/functions.php. View all references

function absint( $maybeint ) {
	return abs( (int) $maybeint );
}


Top ↑

Changelog

Changelog
Version Description
2.5.0 Introduced.

Top ↑

User Contributed Notes

  1. Skip to note 4 content
    Contributed by tradesouthwest

    As to math and floating numbers there are results to consider when using absint. Here are some tests.

    $html .= '<ul>
    <li>0      returns '. absint( 0 ) . '</li>  
    <li>1      returns '. absint( 1 ) . '</li>
    <li>-1     returns '. absint( -1 ) . '</li>
    <li>-1 + 1 returns '. absint( (-1 + 1) ) . '</li>
    <li>1 * -1 returns '. absint( (1 * -1) ) . '</li>
    <li>1 / -1 returns '. absint( (1 / -1) ) . '</li>
    <li>1 - 1  returns '. absint( (1 - 1) ) . '</li>
    <li>0 * -1 returns '. absint( (0 * -1) ) . '</li>
    <li>0 / 1  returns '. absint( (0 / 1) ) . '</li>
    <li>0 - 1  returns '. absint( (0 - 1) ) . '</li>
    <li>0.99 * 1  returns '. absint( (0.99 * 1) ) . '</li>
    <li>1.99 * 1  returns '. absint( (1.99 * 1) ) . '</li>
    <li>0.99 / 1  returns '. absint( (0.99 / 1) ) . '</li>
    <li>1.99 / 1  returns '. absint( (1.99 / 1) ) . '</li>
    </ul>
    <pre><xmp>
        0        returns 0
        1        returns 1
        -1       returns 1
        -1 + 1   returns 0
        1 * -1   returns 1
        1 / -1   returns 1
        1 - 1    returns 0
        0 * -1   returns 0
        0 / 1    returns 0
        0 - 1    returns 1
        0.99 * 1 returns 0
        1.99 * 1 returns 1
        0.99 / 1 returns 0
        1.99 / 1 returns 1
    </xmp></pre>

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