Format to Currency when multiplying/Summing fields

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Targa

    Format to Currency when multiplying/Summing fields

    <input NAME="TAXRATE" onBlur="this.fo rm.TAX.value =
    (this.form.TAXR ATE.value - 0) * (this.form.ITEM 1TOTAL.value - 0) +
    (this.form.ITEM 2TOTAL.value - 0) " Size="4">

    In my TAX field I get something like 1.7500000000000 002.

    Is it possible to format this to read 1.75?

    Also, when summing or multiplying fields, Id like to have 4 x 2.00 = 8.00
    rather than just 8.

    Is this possible?

    Thanks!



  • Janwillem Borleffs

    #2
    Re: Format to Currency when multiplying/Summing fields


    "Targa" <targa1SPAMSUCK S@alltel.net> wrote in message
    news:m8joc.6883 $zq2.1325@fe39. usenetserver.co m...[color=blue]
    > In my TAX field I get something like 1.7500000000000 002.
    >
    > Is it possible to format this to read 1.75?
    >
    > Also, when summing or multiplying fields, Id like to have 4 x 2.00 = 8.00
    > rather than just 8.
    >
    > Is this possible?
    >[/color]

    Read the faq: http://jibbering.com/faq/#FAQ4_6


    JW



    Comment

    • Dr John Stockton

      #3
      Re: Format to Currency when multiplying/Summing fields

      JRS: In article <m8joc.6883$zq2 .1325@fe39.usen etserver.com>, seen in
      news:comp.lang. javascript, Targa <targa1SPAMSUCK S@alltel.net> posted at
      Wed, 12 May 2004 01:05:08 :
      [color=blue]
      ><input NAME="TAXRATE" onBlur="this.fo rm.TAX.value =
      >(this.form.TAX RATE.value - 0) * (this.form.ITEM 1TOTAL.value - 0) +
      >(this.form.ITE M2TOTAL.value - 0) " Size="4">[/color]

      The first two -0 should be unnecessary, also the associated parentheses.

      this.form.TAX.v alue =
      this.form.TAXRA TE.value * this.form.ITEM1 TOTAL.value +
      +this.form.ITEM 2TOTAL.value

      should suffice; note the second + and its being not adjacent to the
      first. FAQ 4.21 refers. But your code does what you expect of it,
      except that ISTM that TAX is not the ideal name for the sum.

      [color=blue]
      >In my TAX field I get something like 1.7500000000000 002.
      >
      >Is it possible to format this to read 1.75?[/color]

      Yes.

      [color=blue]
      >Also, when summing or multiplying fields, Id like to have 4 x 2.00 = 8.00
      >rather than just 8.
      >
      >Is this possible?[/color]

      No. What you need is possible; what you ask for is not.

      You need to think about the distinction between type Number, which is
      the result of multiplication and is an IEEE Double ( 8 will actually be
      represented along the lines of 1.0000*2^3 ), and type String, which is
      a row of keyboard (and sometimes other) characters. Only a String can
      have trailing zeroes.

      Arithmetic results in type Number; various things, including
      document.write, convert Number into String in a rather simple-minded
      manner.

      Method toFixed converts Number to String more suitably; but it is
      unreliable and may not be available.

      See FAQ 4.6. For a choice of conversions, with tests & testers, see in
      <URL:http://www.merlyn.demo n.co.uk/js-round.htm>.

      --
      © John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 IE 4 ©
      <URL:http://jibbering.com/faq/> Jim Ley's FAQ for news:comp.lang. javascript
      <URL:http://www.merlyn.demo n.co.uk/js-index.htm> jscr maths, dates, sources.
      <URL:http://www.merlyn.demo n.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.

      Comment

      Working...