So my problem is that php is not casting these types correctly.. I need to figure out a better way of doing it than number 3, if there is one, and I’d really like to know why PHP treats the comma as a period or something.
$cost = "7,800.00"; // "7,800.00"
$cost = (int) "7,800.00" // int(7)
$cost = (int) preg_replace('/[^-0-9\.]/i', '', "7,800.00"); // int(7800)
Edit, to make things clear to those who don’t read: I’m looking for a more elegant way to do this. As far as why this behavior exists, I’ve already gotten the explanation I was looking for. Thanks.
PHP does not know what to do with the grouping characters (in this case a comma) as it is not a numeric character, period, or
efor exponentiation. So the functions stop parsing when the first non-relevant character is read.Second, have a look at the numeric functions PHP provides:
floatvalandintval