note 101666 added to function.floatval

From: Date: Mon, 03 Jan 2011 16:37:11 +0000
Subject: note 101666 added to function.floatval
Groups: php.notes 
Request: Send a blank email to php-notes+get-175411@lists.php.net to get a copy of this message
setlocale() and floatval() duo could break your DB queries in a very simple way: <?php setlocale(LC_ALL, 'bg_BG', 'bgr_BGR'); echo floatval(0.15); // output 0,15 ?> You would need simple workaround like: <?php function number2db($value) { $larr = localeconv(); $search = array( $larr['decimal_point'], $larr['mon_decimal_point'], $larr['thousands_sep'], $larr['mon_thousands_sep'], $larr['currency_symbol'], $larr['int_curr_symbol'] ); $replace = array('.', '.', '', '', '', ''); return str_replace($search, $replace, $value); } setlocale(LC_ALL, 'bg_BG', 'bgr_BGR'); $testVal = floatval(0.15); // result 0,15 var_dump($testVal, number2db($testVal)); // Result: // float(0,15) // string(4) "0.15" ?> ---- Server IP: 89.190.194.18 Probable Submitter: 109.121.240.162 ---- Manual Page -- http://www.php.net/manual/en/function.floatval.php Edit -- https://master.php.net/note/edit/101666 Del: integrated -- https://master.php.net/note/delete/101666/integrated Del: useless -- https://master.php.net/note/delete/101666/useless Del: bad code -- https://master.php.net/note/delete/101666/bad+code Del: spam -- https://master.php.net/note/delete/101666/spam Del: non-english -- https://master.php.net/note/delete/101666/non-english Del: in docs -- https://master.php.net/note/delete/101666/in+docs Del: other reasons-- https://master.php.net/note/delete/101666 Reject -- https://master.php.net/note/reject/101666 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#175411) next »