Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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.

like image 983
svk Avatar asked Oct 20 '25 10:10

svk


1 Answers

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

like image 102
Pekka Avatar answered Oct 22 '25 02:10

Pekka



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!