Factory::getApplication()->input->getFloat('name') doesn't like decimal numbers that start with a period. For example, ".5" returns the number 5 instead of .5. Looking at the docs, it's easy to see why; the regex that parses the string is "-?[0-9]+(.[0-9]+)?", which requires the number to start with a digit. I have created a custom float parser as follows (making the leading digit optional by replacing + with *):

function customFloat($name, $jinput)
    $source = $jinput->getString($name);
    // modified version of https://docs.joomla.org/Retrieving_request_data_using_JInput for $jinput->getFloat()
    preg_match('/-?[0-9]*(\.[0-9]+)?/', (string) $source, $matches);
    $result = @ (float) $matches[0];
    return $result;

Are there any concerns with this? Why doesn't the standard getFloat() make the leading digit optional?

1 Answer 1


Your question would appear to be better suited to being raised on the Joomla Issue Tracker, https://issues.joomla.org/, where people likely involved in making the original decision or writing the code are likely to see it.

If you include your updated version of the regex you may find someone will pick it up and introduce it into the core. It doesn't look likely to cause any backward compatibility issues so it might be able to be introduced as a fix in 5.x otherwise you might be waiting for 6.0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.