A non well formed numeric value encountered - does this mean










1














I have the following message flagging up when notices are turned on:




Notice: A non well formed numeric value encountered




Does this mean the value expected was not a simple integer? The line referenced is showing this:



$per = ($raw>0?ceil((($raw/$cast)/5)*100):0).'%';










share|improve this question





















  • Add var_dump($raw, $cast); right before this line.
    – Álvaro González
    Feb 14 '17 at 10:34










  • string(2) "14" string(7) "3 votes" - Sounds like they shouldn't be strings I take it?
    – Lee
    Apr 6 '17 at 14:32











  • Hmm I removed the 'votes' output from the variable, and now the error disappears. Maybe that's all it needed.
    – Lee
    Apr 6 '17 at 14:34















1














I have the following message flagging up when notices are turned on:




Notice: A non well formed numeric value encountered




Does this mean the value expected was not a simple integer? The line referenced is showing this:



$per = ($raw>0?ceil((($raw/$cast)/5)*100):0).'%';










share|improve this question





















  • Add var_dump($raw, $cast); right before this line.
    – Álvaro González
    Feb 14 '17 at 10:34










  • string(2) "14" string(7) "3 votes" - Sounds like they shouldn't be strings I take it?
    – Lee
    Apr 6 '17 at 14:32











  • Hmm I removed the 'votes' output from the variable, and now the error disappears. Maybe that's all it needed.
    – Lee
    Apr 6 '17 at 14:34













1












1








1







I have the following message flagging up when notices are turned on:




Notice: A non well formed numeric value encountered




Does this mean the value expected was not a simple integer? The line referenced is showing this:



$per = ($raw>0?ceil((($raw/$cast)/5)*100):0).'%';










share|improve this question













I have the following message flagging up when notices are turned on:




Notice: A non well formed numeric value encountered




Does this mean the value expected was not a simple integer? The line referenced is showing this:



$per = ($raw>0?ceil((($raw/$cast)/5)*100):0).'%';







php






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Feb 14 '17 at 8:05









LeeLee

2,68121242




2,68121242











  • Add var_dump($raw, $cast); right before this line.
    – Álvaro González
    Feb 14 '17 at 10:34










  • string(2) "14" string(7) "3 votes" - Sounds like they shouldn't be strings I take it?
    – Lee
    Apr 6 '17 at 14:32











  • Hmm I removed the 'votes' output from the variable, and now the error disappears. Maybe that's all it needed.
    – Lee
    Apr 6 '17 at 14:34
















  • Add var_dump($raw, $cast); right before this line.
    – Álvaro González
    Feb 14 '17 at 10:34










  • string(2) "14" string(7) "3 votes" - Sounds like they shouldn't be strings I take it?
    – Lee
    Apr 6 '17 at 14:32











  • Hmm I removed the 'votes' output from the variable, and now the error disappears. Maybe that's all it needed.
    – Lee
    Apr 6 '17 at 14:34















Add var_dump($raw, $cast); right before this line.
– Álvaro González
Feb 14 '17 at 10:34




Add var_dump($raw, $cast); right before this line.
– Álvaro González
Feb 14 '17 at 10:34












string(2) "14" string(7) "3 votes" - Sounds like they shouldn't be strings I take it?
– Lee
Apr 6 '17 at 14:32





string(2) "14" string(7) "3 votes" - Sounds like they shouldn't be strings I take it?
– Lee
Apr 6 '17 at 14:32













Hmm I removed the 'votes' output from the variable, and now the error disappears. Maybe that's all it needed.
– Lee
Apr 6 '17 at 14:34




Hmm I removed the 'votes' output from the variable, and now the error disappears. Maybe that's all it needed.
– Lee
Apr 6 '17 at 14:34












3 Answers
3






active

oldest

votes


















4














To reproduce:



var_dump("14" / "3 votes");


(demo)



... prints a warning since PHP/7.1:




Notice: A non well formed numeric value encountered in /in/8dsH7 on
line 3

float(4.6666666666667)




So they apparently added new checks to prevent errors.



Maths with numbers is reliable and well defined. Maths with arbitrary text is not. Or, do you think this makes sense:



var_dump("pink" * "apples");



int(0)







share|improve this answer




























    1














    Are you entering it for an obfuscated code contest or something? :-D . I can't reproduce the notice message, but if you split the code up into separate lines, perhaps you will find out which part of the formula causes the message.



    Why do you check if $raw > 0? If $raw is zero, then $per will simply end up being zero anyway.



    If you're trying to avoid a division by zero error, then you need to be checking $cast, not $raw.



    $per = 0;
    if ($cast > 0)
    $per = ($raw / $cast) / 5 * 100;

    $per .= "%";


    As a final comment, from this fragment of code, it's not clear why you divide by five. It's just a magic number. It would be clearer to make this a constant or variable; at the very least, leave a comment what it is.



    Good luck!






    share|improve this answer






























      1














      Thanks very much for your comments, but after looking at this with fresh eyes, I was able to look abit further into the code, and it dawned on me what was happening.



      As asked above, I dumped the values of $raw and $cast, which were returned as:



      string(2) "14" string(7) "3 votes"


      So clearly, the '3 votes' is supposed to be a number, or the calculation isn't going to work. I had a look at the line above, which read:



      $cast = (get_post_meta($id, '_kksr_casts', true)?get_post_meta($id, '_kksr_casts', true):'0').' votes';


      Bingo. I removed the ending 'votes' output, leaving just the number. And the message disappears. I still want the original text to be outputted though, so I found the next line after 606 contained this:



      $row = $avg . ' (' . $per . ') ' . $cast;


      So I just added 'votes' on the end of this line, which results in the correct output in the WP Admin, and the error now gone.



      Seems fixed, and a pull request created. Thanks for all your help guys.






      share|improve this answer




















        Your Answer






        StackExchange.ifUsing("editor", function ()
        StackExchange.using("externalEditor", function ()
        StackExchange.using("snippets", function ()
        StackExchange.snippets.init();
        );
        );
        , "code-snippets");

        StackExchange.ready(function()
        var channelOptions =
        tags: "".split(" "),
        id: "1"
        ;
        initTagRenderer("".split(" "), "".split(" "), channelOptions);

        StackExchange.using("externalEditor", function()
        // Have to fire editor after snippets, if snippets enabled
        if (StackExchange.settings.snippets.snippetsEnabled)
        StackExchange.using("snippets", function()
        createEditor();
        );

        else
        createEditor();

        );

        function createEditor()
        StackExchange.prepareEditor(
        heartbeatType: 'answer',
        autoActivateHeartbeat: false,
        convertImagesToLinks: true,
        noModals: true,
        showLowRepImageUploadWarning: true,
        reputationToPostImages: 10,
        bindNavPrevention: true,
        postfix: "",
        imageUploader:
        brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
        contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
        allowUrls: true
        ,
        onDemand: true,
        discardSelector: ".discard-answer"
        ,immediatelyShowMarkdownHelp:true
        );



        );













        draft saved

        draft discarded


















        StackExchange.ready(
        function ()
        StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f42220801%2fa-non-well-formed-numeric-value-encountered-does-this-mean%23new-answer', 'question_page');

        );

        Post as a guest















        Required, but never shown

























        3 Answers
        3






        active

        oldest

        votes








        3 Answers
        3






        active

        oldest

        votes









        active

        oldest

        votes






        active

        oldest

        votes









        4














        To reproduce:



        var_dump("14" / "3 votes");


        (demo)



        ... prints a warning since PHP/7.1:




        Notice: A non well formed numeric value encountered in /in/8dsH7 on
        line 3

        float(4.6666666666667)




        So they apparently added new checks to prevent errors.



        Maths with numbers is reliable and well defined. Maths with arbitrary text is not. Or, do you think this makes sense:



        var_dump("pink" * "apples");



        int(0)







        share|improve this answer

























          4














          To reproduce:



          var_dump("14" / "3 votes");


          (demo)



          ... prints a warning since PHP/7.1:




          Notice: A non well formed numeric value encountered in /in/8dsH7 on
          line 3

          float(4.6666666666667)




          So they apparently added new checks to prevent errors.



          Maths with numbers is reliable and well defined. Maths with arbitrary text is not. Or, do you think this makes sense:



          var_dump("pink" * "apples");



          int(0)







          share|improve this answer























            4












            4








            4






            To reproduce:



            var_dump("14" / "3 votes");


            (demo)



            ... prints a warning since PHP/7.1:




            Notice: A non well formed numeric value encountered in /in/8dsH7 on
            line 3

            float(4.6666666666667)




            So they apparently added new checks to prevent errors.



            Maths with numbers is reliable and well defined. Maths with arbitrary text is not. Or, do you think this makes sense:



            var_dump("pink" * "apples");



            int(0)







            share|improve this answer












            To reproduce:



            var_dump("14" / "3 votes");


            (demo)



            ... prints a warning since PHP/7.1:




            Notice: A non well formed numeric value encountered in /in/8dsH7 on
            line 3

            float(4.6666666666667)




            So they apparently added new checks to prevent errors.



            Maths with numbers is reliable and well defined. Maths with arbitrary text is not. Or, do you think this makes sense:



            var_dump("pink" * "apples");



            int(0)








            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Apr 6 '17 at 14:39









            Álvaro GonzálezÁlvaro González

            105k30183272




            105k30183272























                1














                Are you entering it for an obfuscated code contest or something? :-D . I can't reproduce the notice message, but if you split the code up into separate lines, perhaps you will find out which part of the formula causes the message.



                Why do you check if $raw > 0? If $raw is zero, then $per will simply end up being zero anyway.



                If you're trying to avoid a division by zero error, then you need to be checking $cast, not $raw.



                $per = 0;
                if ($cast > 0)
                $per = ($raw / $cast) / 5 * 100;

                $per .= "%";


                As a final comment, from this fragment of code, it's not clear why you divide by five. It's just a magic number. It would be clearer to make this a constant or variable; at the very least, leave a comment what it is.



                Good luck!






                share|improve this answer



























                  1














                  Are you entering it for an obfuscated code contest or something? :-D . I can't reproduce the notice message, but if you split the code up into separate lines, perhaps you will find out which part of the formula causes the message.



                  Why do you check if $raw > 0? If $raw is zero, then $per will simply end up being zero anyway.



                  If you're trying to avoid a division by zero error, then you need to be checking $cast, not $raw.



                  $per = 0;
                  if ($cast > 0)
                  $per = ($raw / $cast) / 5 * 100;

                  $per .= "%";


                  As a final comment, from this fragment of code, it's not clear why you divide by five. It's just a magic number. It would be clearer to make this a constant or variable; at the very least, leave a comment what it is.



                  Good luck!






                  share|improve this answer

























                    1












                    1








                    1






                    Are you entering it for an obfuscated code contest or something? :-D . I can't reproduce the notice message, but if you split the code up into separate lines, perhaps you will find out which part of the formula causes the message.



                    Why do you check if $raw > 0? If $raw is zero, then $per will simply end up being zero anyway.



                    If you're trying to avoid a division by zero error, then you need to be checking $cast, not $raw.



                    $per = 0;
                    if ($cast > 0)
                    $per = ($raw / $cast) / 5 * 100;

                    $per .= "%";


                    As a final comment, from this fragment of code, it's not clear why you divide by five. It's just a magic number. It would be clearer to make this a constant or variable; at the very least, leave a comment what it is.



                    Good luck!






                    share|improve this answer














                    Are you entering it for an obfuscated code contest or something? :-D . I can't reproduce the notice message, but if you split the code up into separate lines, perhaps you will find out which part of the formula causes the message.



                    Why do you check if $raw > 0? If $raw is zero, then $per will simply end up being zero anyway.



                    If you're trying to avoid a division by zero error, then you need to be checking $cast, not $raw.



                    $per = 0;
                    if ($cast > 0)
                    $per = ($raw / $cast) / 5 * 100;

                    $per .= "%";


                    As a final comment, from this fragment of code, it's not clear why you divide by five. It's just a magic number. It would be clearer to make this a constant or variable; at the very least, leave a comment what it is.



                    Good luck!







                    share|improve this answer














                    share|improve this answer



                    share|improve this answer








                    edited Feb 14 '17 at 10:59

























                    answered Feb 14 '17 at 9:03









                    Ben HillierBen Hillier

                    1,7131610




                    1,7131610





















                        1














                        Thanks very much for your comments, but after looking at this with fresh eyes, I was able to look abit further into the code, and it dawned on me what was happening.



                        As asked above, I dumped the values of $raw and $cast, which were returned as:



                        string(2) "14" string(7) "3 votes"


                        So clearly, the '3 votes' is supposed to be a number, or the calculation isn't going to work. I had a look at the line above, which read:



                        $cast = (get_post_meta($id, '_kksr_casts', true)?get_post_meta($id, '_kksr_casts', true):'0').' votes';


                        Bingo. I removed the ending 'votes' output, leaving just the number. And the message disappears. I still want the original text to be outputted though, so I found the next line after 606 contained this:



                        $row = $avg . ' (' . $per . ') ' . $cast;


                        So I just added 'votes' on the end of this line, which results in the correct output in the WP Admin, and the error now gone.



                        Seems fixed, and a pull request created. Thanks for all your help guys.






                        share|improve this answer

























                          1














                          Thanks very much for your comments, but after looking at this with fresh eyes, I was able to look abit further into the code, and it dawned on me what was happening.



                          As asked above, I dumped the values of $raw and $cast, which were returned as:



                          string(2) "14" string(7) "3 votes"


                          So clearly, the '3 votes' is supposed to be a number, or the calculation isn't going to work. I had a look at the line above, which read:



                          $cast = (get_post_meta($id, '_kksr_casts', true)?get_post_meta($id, '_kksr_casts', true):'0').' votes';


                          Bingo. I removed the ending 'votes' output, leaving just the number. And the message disappears. I still want the original text to be outputted though, so I found the next line after 606 contained this:



                          $row = $avg . ' (' . $per . ') ' . $cast;


                          So I just added 'votes' on the end of this line, which results in the correct output in the WP Admin, and the error now gone.



                          Seems fixed, and a pull request created. Thanks for all your help guys.






                          share|improve this answer























                            1












                            1








                            1






                            Thanks very much for your comments, but after looking at this with fresh eyes, I was able to look abit further into the code, and it dawned on me what was happening.



                            As asked above, I dumped the values of $raw and $cast, which were returned as:



                            string(2) "14" string(7) "3 votes"


                            So clearly, the '3 votes' is supposed to be a number, or the calculation isn't going to work. I had a look at the line above, which read:



                            $cast = (get_post_meta($id, '_kksr_casts', true)?get_post_meta($id, '_kksr_casts', true):'0').' votes';


                            Bingo. I removed the ending 'votes' output, leaving just the number. And the message disappears. I still want the original text to be outputted though, so I found the next line after 606 contained this:



                            $row = $avg . ' (' . $per . ') ' . $cast;


                            So I just added 'votes' on the end of this line, which results in the correct output in the WP Admin, and the error now gone.



                            Seems fixed, and a pull request created. Thanks for all your help guys.






                            share|improve this answer












                            Thanks very much for your comments, but after looking at this with fresh eyes, I was able to look abit further into the code, and it dawned on me what was happening.



                            As asked above, I dumped the values of $raw and $cast, which were returned as:



                            string(2) "14" string(7) "3 votes"


                            So clearly, the '3 votes' is supposed to be a number, or the calculation isn't going to work. I had a look at the line above, which read:



                            $cast = (get_post_meta($id, '_kksr_casts', true)?get_post_meta($id, '_kksr_casts', true):'0').' votes';


                            Bingo. I removed the ending 'votes' output, leaving just the number. And the message disappears. I still want the original text to be outputted though, so I found the next line after 606 contained this:



                            $row = $avg . ' (' . $per . ') ' . $cast;


                            So I just added 'votes' on the end of this line, which results in the correct output in the WP Admin, and the error now gone.



                            Seems fixed, and a pull request created. Thanks for all your help guys.







                            share|improve this answer












                            share|improve this answer



                            share|improve this answer










                            answered Apr 6 '17 at 14:45









                            LeeLee

                            2,68121242




                            2,68121242



























                                draft saved

                                draft discarded
















































                                Thanks for contributing an answer to Stack Overflow!


                                • Please be sure to answer the question. Provide details and share your research!

                                But avoid


                                • Asking for help, clarification, or responding to other answers.

                                • Making statements based on opinion; back them up with references or personal experience.

                                To learn more, see our tips on writing great answers.





                                Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                                Please pay close attention to the following guidance:


                                • Please be sure to answer the question. Provide details and share your research!

                                But avoid


                                • Asking for help, clarification, or responding to other answers.

                                • Making statements based on opinion; back them up with references or personal experience.

                                To learn more, see our tips on writing great answers.




                                draft saved


                                draft discarded














                                StackExchange.ready(
                                function ()
                                StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f42220801%2fa-non-well-formed-numeric-value-encountered-does-this-mean%23new-answer', 'question_page');

                                );

                                Post as a guest















                                Required, but never shown





















































                                Required, but never shown














                                Required, but never shown












                                Required, but never shown







                                Required, but never shown

































                                Required, but never shown














                                Required, but never shown












                                Required, but never shown







                                Required, but never shown







                                這個網誌中的熱門文章

                                How to read a connectionString WITH PROVIDER in .NET Core?

                                Node.js Script on GitHub Pages or Amazon S3

                                Museum of Modern and Contemporary Art of Trento and Rovereto