filter sanizite user input float numbers comma/dot issue

Viewed 2315

Trying to figure out how to user filters in php in a sensible way

//Do sanization of user input
//$_POST['amount_ecb'] can be 77,7 or 77.7

$amount = filter_input(INPUT_POST, 'amount_ecb', 
FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION); 

if posted value is 77.7 it sets amount correctly, but if user sets number with a comma instead of a dot (eg. 77,7) $amount returns 77

I want it to return 77.7 in both cases. Is this possible to solve with filters?

UPDATE After feedback (posted answer) I still have the same issue:

When using

$_POST['amount_ecb'] = str_replace(',', '.', $_POST['amount_ecb']);

before

This it was it returns

$_POST object

array (size=5)
  'amount_ecb' => string '77.7' (length=4)
  'from_ecb' => string 'GBP' (length=3)
  'to_ecb' => string 'SEK' (length=3)
  'submit' => string 'Calculate currency' (length=18)
  'result_decimals' => string '4' (length=1)

$amount

string '777' (length=3)
2 Answers
Related