Re: Thousands Separator
| From: | Jeffry Killen | Date: | Sat, 17 Jan 2015 01:11:49 +0000 |
| Subject: | Re: Thousands Separator | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-324266@lists.php.net to get a copy of this message | ||
On Jan 16, 2015, at 3:37 PM, Christoph Becker wrote:
Jeffry Killen wrote:Actually what should work with settype isSorry, there is a misunderstanding on my part here: On Jan 16, 2015, at 2:31 PM, Jeffry Killen wrote:One could use intval()/floatval() or an (int)/(float) cast instead.Here is some more that you may find useful: In your hypothetical example: $num = '123_456_789', $num is a string. and I presume you mean that this is hard coded into your source file code and you want to be able to read the source code with greater ease. So you can hard code it this way and if you want to use the value as an actual number in some mathmatical processing:settype does not return anything accept true or false.
I got this to work <?php $num = '123_456_789'; $num = str_replace('_', '', $num); settype($num, 'int'); print "\$num += 1: ".$num += 1; ?>$num = '123_456_789'; settype(str_replace('_', '', $num), 'int') settype should coerce the data type in place to an int. (of float if you use 'float' as the second argument to settype
settype(str_replace('_', '', '123_456_789'), 'int'); or-- $num = '123_456_789'; function use($num) { settype(str_replace('_', '', $num), 'int') } $num = use($num); Or settype( string, 'float') if there is a decimal fraction involved.