Format to Currency when multiplying/Summing fields

T

Targa

<input NAME="TAXRATE" onBlur="this.form.TAX.value =
(this.form.TAXRATE.value - 0) * (this.form.ITEM1TOTAL.value - 0) +
(this.form.ITEM2TOTAL.value - 0) " Size="4">

In my TAX field I get something like 1.7500000000000002.

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!
 
D

Dr John Stockton

JRS: In article <[email protected]>, seen in
<input NAME="TAXRATE" onBlur="this.form.TAX.value =
(this.form.TAXRATE.value - 0) * (this.form.ITEM1TOTAL.value - 0) +
(this.form.ITEM2TOTAL.value - 0) " Size="4">

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

this.form.TAX.value =
this.form.TAXRATE.value * this.form.ITEM1TOTAL.value +
+this.form.ITEM2TOTAL.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.

In my TAX field I get something like 1.7500000000000002.

Is it possible to format this to read 1.75?
Yes.


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

Is this possible?

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.demon.co.uk/js-round.htm>.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top