Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Convert string to number format in Laravel

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

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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);
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading