Solved

Problem with number_format

Posted on 2014-11-11
3
88 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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
These days socially coordinated efforts have turned into a critical requirement for enterprises.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

786 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