|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2006-08-18 05:28 UTC] x dot philbert at pixandlog dot net
Description:
------------
Hello.
With decimal option, it's not possible to check two
differents float.
Users type either '42.42' or '42,42'. But it's not easy to
force user to type one style of float.
How use decimal option with mutli parameters ?
But with separator flag how do you do difference ?
Example : '1,597,541.42' english style ?
'5 999 741,487' french style ?
'987412.42' user style ;)
'4870,42' user style ;)
'4, 454, 454. 42' other style.
It's not easy to determine the right way.
Thank you for your job.
Reproduce code:
---------------
<?php
//$_GET['test1'] = '42,42';
//$_GET['test2'] = '42.42';
$test1 = input_get(INPUT_GET, 'test1', FILTER_VALIDATE_FLOAT, array('decimal' => ','));
var_dump($test1);
$test2 = input_get(INPUT_GET, 'test2', FILTER_VALIDATE_FLOAT);
var_dump($test2);
$test1 = input_get(INPUT_GET, 'test1', FILTER_VALIDATE_FLOAT);
var_dump($test1);
$test2 = input_get(INPUT_GET, 'test2', FILTER_VALIDATE_FLOAT, array('decimal' => ','));
var_dump($test2);
?>
Expected result:
----------------
float(42.42);
float(42.42);
float(42.42);
float(42.42);
Actual result:
--------------
float(42.42);
float(42.42);
bool(false);
bool(false);
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Tue Dec 30 12:00:01 2025 UTC |
Yes. It s very hard to allow many separators for one call. But i find on forum this help. I write this comment because it's a good way for check locales informations. This code is a part of Zend Framework. /** * Returns value if it is a valid float value, FALSE otherwise. * * @param mixed $value * @return mixed */ public static function isFloat($value) { $locale = localeconv(); $value = str_replace($locale['decimal_point'], '.', $value); $value = str_replace($locale['thousands_sep'], '', $value); return (strval(floatval($value)) == $value); } Why don't verif locale value with localeconv in C code ? Good work, continue please for the next release.