Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

felicia00's avatar

Hit error number_format() expects parameter 1 to be float, string given

May i know why would i keep hitting this error :(

                    <?php
                            $prc = 0.00;
                            $claim_prc = 0.00;
                            $sum = 0.00;
                            $variation = 0.00;
                        ?>


                        @foreach($respDtl as $index=>$dtl)

                        <?php
                            $prc += number_format($dtl->value,2,'.','');
                            $claim_prc += number_format($dtl->claimed_price,2,'.','');
                            $sum += number_format($dtl->sumtotal,2,'.','');
                            $variation += number_format(number_format($dtl->claimed_price,2,'.','')- 
                          number_format($dtl->value,2,'.',''),2,'.','');
                        ?>
0 likes
2 replies
Nakov's avatar

@felicia00 the error is pretty clear. The first parameter that you are passing to the number_format function is String.. ie "SOME TEXT" while it needs to be a number, like 1.0 or "1.0".

I think this one is the problem:

number_format(number_format($dtl->claimed_price,2,'.','') - number_format($dtl->value,2,'.',''),2,'.','');

You don't need to format numbers that are already formatted.

automica's avatar

@felicia00 firstly I don't think you need to do number formatting as you are adding up, but also I wouldn't do this loop in your blade at all.

Do processing in your controller and then pass in the data into your blade afterwards to render the results.

Please or to participate in this conversation.