I have script that identifies with preg_match_all
some numbers from a given file and in a given format '#(\d\,\d\d\d\d)#'
(decimal, with 4 decimals). With them, later, I need to do some math operations to find out the sum, average etc.
With print_r
I can see all matches from the array and it is ok (4,3456, 4,9098, etc.). I verify the type of variables and gettype()
returned string
Unfortunately I cannot do math operations with them because when I use the variables in a math expression the result is always rounded regardless of what came afer the comma.
For example:
4,3456 + 4,9098 + 4,3456 = 12, or 12,0000 -- if I use number_format
.
I used .
instead of ,
in the numbers, I formatted the results with number_format
, but have had no success. It seems I am missing something.
Thanks for help!