>>Can anyone see why?

Nope, but decimalformat returns number to 2 decimal places, probably
javascript rounding issue

CF to 2 decimal places....
<cfset nope=14.779999999999999>
<cfoutput>#DecimalFormat(nope)#</cfoutput><br>
gives 14.78

more to the point,
maybe use Math.round in javascript, see
http://www.experts-exchange.com/Web/Web_Languages/JavaScript/Q_10077580.html


rgds


Colm

Colm Brazel MA
CB Publications

www.cbweb.net <http://www.cbweb.net>
[EMAIL PROTECTED] <mailto:design@;cbweb.net>
[EMAIL PROTECTED] <mailto:cbweb@;iol.ie>






-----Original Message-----
From: Giles Roadnight [mailto:giles.roadnight@;goldcockerelbooks.co.uk]
Sent: 22 October 2002 17:17
To: [EMAIL PROTECTED]
Subject: [ cf-dev ] OT: Javascript prob.


I have a form with a list of input boxes. The first of which has the
price of the item in a hidden field, the second of which is a textbox
with a default value of 0. This script is supposed to loop through all
of the text boxes two at a time and multiply the text box pointed to by
I (the text box quantity field) by the text box pointed to by i-1 (the
price). This works fine except for when it adds three items together at
�5.25, �5.60 and �4.55 when I get 15.399999999999998 instead of 15.40.

Can anyone see why?

Thanks

function calculateTotal(textBox){
        if(isNaN(textBox.value)){
                alert("Please only enter numbers into the quantity
field")
                textBox.value = 0;
        }
        var formTotal = 0;
        for(i=1;i<textBox.form.elements.length-3;i += 2){
                formTotal +=
parseFloat(textBox.form.elements[i-1].value) *
parseInt(textBox.form.elements[i].value);
        }
        formTotal += ''
        if(formTotal.indexOf('.') == -1){
                formTotal += '.00';
        } else {
                if(formTotal.length - formTotal.indexOf('.') == 2){
                        formTotal += '0';
                }
        }
        textBox.form.total.value = formTotal;
}


Giles Roadnight
http://giles.roadnight.name




--
** Archive: http://www.mail-archive.com/dev%40lists.cfdeveloper.co.uk/

To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
For human help, e-mail: [EMAIL PROTECTED]

---
Incoming mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.394 / Virus Database: 224 - Release Date: 10/3/2002

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.394 / Virus Database: 224 - Release Date: 10/3/2002


-- 
** Archive: http://www.mail-archive.com/dev%40lists.cfdeveloper.co.uk/

To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
For human help, e-mail: [EMAIL PROTECTED]

Reply via email to