Wrox Home  
Search P2P Archive for: Go

  Return to Index  

javascript thread: Formatting Numbers in Javascript


Message #1 by "Laphan" <laphan@u...> on Sun, 22 Oct 2000 12:20:40 +0100
Hi All

Laphan here tearing large lumps of hair out.

I have the following code in a Javascript client-side function:

if (dest == 'C') {
  numPanels = Number(document.all["PANEL1"].innerText) +
Number(document.all["PANEL2"].innerText);

if (numPanels <= 40) {
  numCarriage = numPanels * 1.00;
  }
if (numPanels > 40 && numPanels <= 80) {
  numCarriage = numPanels * 5.00;
  }
if (numPanels > 80 && numPanels <= 120) {
  numCarriage = numPanels * 100.00;
  }

  document.all["post"].innerText = numCarriage;
  parent.itemlist[3].price = numCarriage;

It's a simple function that multiplies a variable by the respective above
amount and then puts it on to the page and into a global array. 
Everything
works fine apart from if the value comes out at 4.50 or 6.00, bloody
Javascript goes and rounds it to 4.5 or 6

Is there some form of format function in Javascript, like the FormatNumber
option in VBScript, that will allow me to keep it at 4.50 and 6.00?

Many thanks for any advice you can give.

Regards

Laphan



  Return to Index