[SOLVED] Check if number is decimal

Issue

I need to check in PHP if user entered a decimal number (US way, with decimal point: X.XXX)

Any reliable way to do this?

Solution

You can get most of what you want from is_float, but if you really need to know whether it has a decimal in it, your function above isn’t terribly far (albeit the wrong language):

function is_decimal( $val )
{
    return is_numeric( $val ) && floor( $val ) != $val;
}

Answered By – cwallenpoole

Answer Checked By – Marie Seifert (BugsFixing Admin)

Leave a Reply

Your email address will not be published. Required fields are marked *