469,923 Members | 1,650 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,923 developers. It's quick & easy.

Format to Currency when multiplying/Summing fields

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

Jul 23 '05 #1
2 3167

"Targa" <ta*************@alltel.net> wrote in message
news:m8*****************@fe39.usenetserver.com...
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?


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

Jul 23 '05 #2
JRS: In article <m8*****************@fe39.usenetserver.com>, seen in
news:comp.lang.javascript, Targa <ta*************@alltel.net> posted at
Wed, 12 May 2004 01:05:08 :
<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>.

--
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.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
Jul 23 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by adegreiff | last post: by
3 posts views Thread by jason | last post: by
3 posts views Thread by Abby Lee | last post: by
2 posts views Thread by VB Programmer | last post: by
6 posts views Thread by KevinW | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.