Solved

Problem with number_format

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

Expert Comment

by:Dave Baldwin
Comment Utility
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
Comment Utility
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
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

This article will explain how to display the first page of your Microsoft Word documents (e.g. .doc, .docx, etc...) as images in a web page programatically. I have scoured the web on a way to do this unsuccessfully. The goal is to produce something …
Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

762 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

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now