Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Input type number not showing decimal values.

Posted on 2015-01-07
7
Medium Priority
?
279 Views
Last Modified: 2015-01-11
I have an input field defined as numeric.  I'm trying to get it to show the decimal places.  Here's the code:

if ($ROW['RENT'] == "0")
            {
                  if ($ROW['TOTAL'] == "0")
                  {
                        $work = "0";
                  }
                  else
                  {
                        $work = ("$ROW[ANNUAL]" / "$ROW[TOTAL]");
                  }
            }
            else
            {
                  $work = number_format("$ROW[RENT]");
            }
            $work = number_format($work, 2, '.', '');
                  
            echo '<td align = "right">';
            echo '<input type="number" name="$PSF" size = "9" value="';
            echo $work;
            echo '" maxlenghth="9" step = "0.01">';
            echo '</td>';

What am I missing?

Thanks
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
  • 3
7 Comments
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 40536866
This worked well for me in Chrome.

<?php // demo/temp_breeze351.php

/**
 * HOW TO MAKE AN HTML5 INPUT TYPE=NUMBER CONTROL SHOW DECIMALS
 *
 * SEE: http://www.experts-exchange.com/Programming/Languages/Scripting/PHP/Q_28592569.html
 * REF: http://www.w3.org/TR/html-markup/input.number.html
 */
error_reporting(E_ALL);

/**
 * SHOW THE REQUEST INFORMATION
 */
if (!empty($_POST)) var_dump($_POST);

/**
 * CREATE THE HTML5 FORM
 */
$form = <<<EOD
<form method="post">
Number:
<input type="number" min="0.00" max="1.00" step="0.01" placeholder="0.00 to 1.00" name="n" style="width:8em;" />
<input type="submit" />
</form>
EOD;

echo $form;

Open in new window

0
 
LVL 84

Expert Comment

by:Dave Baldwin
ID: 40536950
"$PSF" is not a 'legal' name.  As told in this document http://www.w3.org/TR/1999/REC-html401-19991224/types.html#type-cdata
ID and NAME tokens must begin with a letter ([A-Za-z]) and may be followed by any number of letters, digits ([0-9]), hyphens ("-"), underscores ("_"), colons (":"), and periods (".").
Also note that any 'id's used in javascript are case sensitive.
0
 

Author Comment

by:breeze351
ID: 40538445
No joy!
I modifed the input statement to read:
echo '<input type="number" name="PSF" size = "7" min = "0.00" max = "9999.99" value="';
            echo $work;
            echo '" maxlenghth="7" step = "0.01">';

The value of $ROW[RENT] for this record is 750.00

Viewing the source in FireFox shows:

<input type="number" name="PSF" size = "7" min = "0.00" max = "9999.99" value="750.00" maxlenghth="7" step = "0.01">

The display still shows "750".  If i increment it does change to "750.01".

Any ideas?
0
Survive A High-Traffic Event with Percona

Your application or website rely on your database to deliver information about products and services to your customers. You can’t afford to have your database lose performance, lose availability or become unresponsive – even for just a few minutes.

 
LVL 84

Expert Comment

by:Dave Baldwin
ID: 40538505
In most languages, leading zeros and all zeros after the decimal point are discarded because they are meaningless.  If you want the value of '750.00' to show you will probably have to use type="text" and not number.  If you change it to '750.10', it will probably show as '750.1'.
0
 

Author Comment

by:breeze351
ID: 40538572
If I change the input type to "text", I would be hoping that the user doesn't enter "ABCDEF".
0
 
LVL 84

Accepted Solution

by:
Dave Baldwin earned 2000 total points
ID: 40541746
So what will you do?  You can't get what you want with <input type="number"...  And it works the same way in Firefox and Chrome.
0
 

Author Closing Comment

by:breeze351
ID: 40543603
I've done some searching around and it appears that using "text" I need to add a "pattern" to the input statement.  I've tried a couple of different patterns with varying results but they created other problems.

I'm going to post the same question to HTML and see what they suggest.

Thanks

Glenn
0

Featured Post

Understanding Web Applications

Without even knowing it, most of us are using web applications on a daily basis. Gmail and Yahoo email, Twitter, Facebook, and eBay are used by most of us daily—and they are web applications. We often confuse these web applications tools for websites.  So, what is the difference?

Question has a verified solution.

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

When crafting your “Why Us” page, there are a plethora of pitfalls to avoid. Follow these five tips, and you’ll be well on your way to creating an effective page.
Originally, this post was published on Monitis Blog, you can check it here . Websites are getting bigger and more complicated by the day. Video, images and custom fonts are all great for showcasing your product or service. But the price to pay in…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
Shows how to create a shortcut to site-search Experts Exchange using Google in the Chrome browser. This eliminates the need to type out site:experts-exchange.com whenever you want to search the site. Launch the Search Engine Menu: In chrome, via you…

715 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