I'm trying to convert a string number like 14,767
or 96,812.10
or 6,780,766.50
but if I use
(double)$fildOfDataBase
or (float)$fildOfDataBase
this put a integer format as 14 o 96 and I don't know why, so my question is how can i convert a string to a number format, hope some one can help me I'm using laravel 8
CodePudding user response:
You need to remove the thousands separator first
(float)str_replace(',', '', $fildOfDataBase);
Another more "strict" way to do it is to use numfmt_parse
//in your case use the en_EN format
$fmt = numfmt_create( 'en_EN', NumberFormatter::DECIMAL );
numfmt_parse($fmt, $fildOfDataBase);