Solved

Problem with number_format

Posted on 2014-11-11
3
89 Views
Last Modified: 2014-11-11
I can't see the problem with this.
<?php
                        if ($ROW['BASEMENT'] == "0")
                        {
                              $work = "";
                        }
                        else
                        {
                      $work = number_format("$ROW[BASEMENT]");
                        }
                        echo $work;
                        ?>
                  </td>
         
            <td width = 5% class = "Space_Display" style="padding-left:15px">Ceiling:
                  </td>
           
            <td width = 10% class = "Space_Display" align="right" style="padding-left:15px">
                        <?php
                        if ($ROW['CEILING'] == "0")
                        {
                              $work = "";
                        }
                        else
                        {
                              $work = number_format("$ROW[CEILING]");
                        }
                        echo $work;
                        ?>
                  </td>

$ROW[BASEMENT] WORKS but  $ROW[CEILING] returns the following error:

Warning: number_format() expects parameter 1 to be double, string given in /home/mrbreeze/public_html/chris/Space_Display.php on line 267

WTF?

Thanks
Glenn
0
Comment
Question by:breeze351
3 Comments
 
LVL 83

Expert Comment

by:Dave Baldwin
ID: 40436235
Assuming there is nothing but numbers in your string, the easiest thing is to multiply it by 1 so PHP thinks it's  number.  If it starts with numbers but has text after the numbers, that usually still works.  But if it starts with text or punctuation, then it won't, it will just be a string.
0
 
LVL 15

Accepted Solution

by:
ChloesDad earned 500 total points
ID: 40436266
Why have you put the $ROW[CEILING] inside speech marks, as I think that this will then try and turn the text "$ROW[CEILING]" into a number rather than the content of $ROW[CEILING] into a number.
0
 

Author Closing Comment

by:breeze351
ID: 40436382
My bad!!!!  I've been dealing with customers since the 80's.  I should know better than to trust what they say.  They provided the database.  "You're code is F!!!! up.  Ceiling is a numeric!!!"  Guess what, "12" is a numeric but "12'6" (as in 12 feet 6 inches) is not.
Thanks
Glenn
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

792 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question