Solved

Problem with number_format

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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone 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

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…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
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 look for a specific file type in a local or remote server directory using PHP.

756 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