0

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

gutiec
  • 13
  • 5
  • Does this answer your question? [Unformat money when parsing in PHP](https://stackoverflow.com/questions/5139793/unformat-money-when-parsing-in-php) – steven7mwesigwa Apr 11 '22 at 17:14

1 Answers1

1

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);
N69S
  • 16,110
  • 3
  • 22
  • 36