Solved

floating point precision in an HTML text field

Posted on 2001-09-10
1
197 Views
Last Modified: 2008-03-03
At this URL
http://www.cadenzasoftware.com/sample/printing/form.htm
I need the price field to always show two decimal points precision.  As it is now, two decimal points are shown only when the page loads, because I have initialized the price field to 150.00.  Play with the fields and controls and you will see that the fractional part goes away.  All of the floating point values that I use in the script have two decimal places, even 0.00.  How do I maintain two decimal places in the price field?
0
Comment
Question by:myudt
[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
1 Comment
 
LVL 2

Accepted Solution

by:
psogaa earned 100 total points
ID: 6470601
Use this function.
Then in your printing.js, replace the following line:

document.quote.price.value = price;

with:

document.quote.price.value = FormatNumber(price,2);


function FormatNumber(expr, decplaces) {
  var str = "" + Math.round(eval(expr) * Math.pow(10,decplaces));
  while (str.length <= decplaces){
    str = "0" + str;
  }
  var decpoint = str.length - decplaces;
  return str.substring(0,decpoint) + "." + str.substring(decpoint, str.length);
}
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to pass values to HTML-5 attribute dynamically? 24 69
Read text on Table 7 49
Make New Browser Window Fully Functional 7 36
Jquery syntax 12 30
I've been trying to accomplish this for a while and it just struck me yesterday how to accomplish this task. I have done searches all over the internet looking for ways to email pages from my applications and finally I have done it!!! Every single s…
In Part 1 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7849-Hex-Maze.html) we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
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)
The viewer will learn the basics of jQuery including how to code hide show and toggles. 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…

759 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