Solved

Problem with number_format

Posted on 2014-11-11
3
93 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

WordPress Tutorial 2: Terminology

An important part of learning any new piece of software is understanding the terminology it uses. Thankfully WordPress uses fairly simple names for everything that make it easy to start using the software.

Question has a verified solution.

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

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this. Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it i…
This article discusses how to implement server side field validation and display customized error messages to the client.
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…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

636 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