Skip to content
Advertisement

Format number in array within an array_sum

I have a view in a laravel project where I have to print the sum of some array columns.

I Have this kind of code to achieve the result:

JavaScript

It works fine. But there is a problem.

The numeric columns have a formatted italian currency number like this:

1.267,76 €

So the sum is printed wrong, because numbers have wrong format to perform the sum.

How can format all the numbers to 1267.76 before performing the sum within blade view?

Thanks

Advertisement

Answer

Ok, I’m trying to find the solution from yesterday. Now I found it on myself few minutes after I posted the question.

I modified the code to get the sum in this way:

JavaScript

Using str_replace with array_column the formatted currency numbers were replaced with standard numbers. Then number_format print the sum with original format.

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement