Skip to content
Advertisement

Is it possible to filter the integer with decimal points using filter_var in PHP?

I need to filter the value like this 100.50 using filter_var in PHP. Now I am using like this
filter_var($_POST['amount'],FILTER_SANITIZE_NUMBER_INT) : '';
And it gives me the result is 10050 .
How can I solve this problem.
Thanks in advance.

Advertisement

Answer

An integer does not have decimal fractions, so the validation must fail (although I find the sanitation result of 100.50 turning into 10050 pretty bizarre on PHP’s end. WTF?).

You would need to use a different filter, e.g. FILTER_VALIDATE_FLOAT.

List of PHP validate filters

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement