计算表格中的运费 [英] Calculating shipping cost in a form

查看:54
本文介绍了计算表格中的运费的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 http:// www。 develop.check.com.au/hh/order.html 其中

一个扩展小计,然后计算一个总计

a数量由用户输入。我希望能够将

运费加到该总额中。


运费在邮资和邮件中处理费用链接,每箱价格为
。如果有人选择美国,加拿大,中东,从

下拉框中它应该重新计算运费,否则它将在默认情况下计算
。澳大利亚。


如果我在这里发布计算函数,它们将会换行,但它们位于
http://www.develop.check.com.au/hh/calculate2.js

很多TIA的帮助。

解决方案

Howard Martin写道:

我的表格在 http://www.develop.check.com.au/hh/order.html 其中<一旦用户输入数量,就会计算扩展的子总数,然后计算总计。我希望能够将
运费加到该总额上。

运费在邮资和邮件中。处理费用链接,是每箱的成本。如果有人选择美国,加拿大,中东,从
下拉框中它应该重新计算运费,否则它应该在默认情况下计算 - 澳大利亚。 caculate2.js计算





运费=新数组(''5.00'',''7.50'',''8.50 '','''9.50'');


函数总数(what,number){

var grandTotal = 0;

var quantTotal = 0;

for(var i = 0; i< number; i ++){

if(what.elements [''price''+ i] .value =='''')

what.elements [''price''+ i] .value =''0.00''; //修复Opera。


what.elements [''subtotal''+ i] .value =(what.elements [''quantity''+ i] .value

- 0)*(what.elements [''price''+ i] .value - 0);

if(what.elements [''quantity''+ i ] .value ==" 0")

what.elements [''subtotal''+ i] .value =" 0.00" ;;


subtotal = what.elements [''subtotal''+ i] .value

grandTotal + =(what.elements [''price''+ i] .value - 0)*

(what.elements [''quantity''+ i] .value - 0);


quantTotal + = what.elements [''quantity''+ i ] .value * 1;

}


shippingCost = quantTotal *

运费[what.elements [''location'' ] .selectedIndex];


shippingCost = quantTotal> 200? shippingCost * 0.8:

quantTotal> 100? shippingCost * 0.9:

quantTotal> 50? shippingCost * 0.95:

shippingCost * 1;

grandTotal + = shippingCost;


小计=舍入(Math.round(小计) * Math.pow(10,2))/ Math.pow(10,2));

what.grandTotal.value =

roundoff(Math.round(grandTotal) * Math.pow(10,2))/ Math.pow(10,2));


}

如果我在这里发布计算函数将包裹,但他们在
http: //www.develop.check.com.au/hh/calculate2.js




计算:


shipping = new Array(''5.00'',''7.50'',''8.50'',''9.50'');


function total2(what){

var quantTotal = 0;

var j = 0;

for(var i = 0; i< what.length; i ++)

if(what.elements [i] .name.substring(0,4)==''quant'')

j ++;

for(var i = 0; i< j; i ++)

quantTotal + = what.element s [''quantity''+ i] .value * 1;

shippingCost = quantTotal *

运费[what.elements [''location'']。selectedIndex] ;

shippingCost = quantTotal> 200? shippingCost * 0.8:

quantTotal> 100? shippingCost * 0.9:

quantTotal> 50? shippingCost * 0.95:

shippingCost * 1;

what.grandTotal.value + = shippingCost;

what.grandTotal.value = roundoff(Math .round(what.gra ndTotal.value * Math.pow(10,2))/ Math.pow(10,2));

}

-

Stephane Moriaux et son [moins] vieux Mac


JRS:文章< 42 ************ *********@news.wanadoo.fr> ;,日期为星期二,

2005年7月19日03:59:12,见于新闻:comp.lang.javascript,ASM< stephanemo
ri***********@wanadoo.fr >发表:

Howard Martin写道:

我的表格在 http://www.develop.check.com.au/hh/order.html 其中


计算caculate2.js :
grandTotal + =(what.elements [''price''+ i] .value - 0)*
(what.elements [''quantity''+ i] .value - 0);




乘法之前,无需将String显式转换为数字。


quantTotal + = what。元素[ '' 量 '' + I]。价值* 1;


无需乘以1即可将String转换为Number;一元一天+

更优雅。

见常见问题。


小计=舍入(Math.round(小计*数学) .pow(10,2))/ Math.pow(10,2));
what.grandTotal.value =
舍入(Math.round(grandTotal * Math.pow(10,2)) /Math.pow(10,2));




Math.pow(10,2)*总是* 100;没有必要计算每个

时间,甚至一次。并且没有定义舍入。


-

?约翰斯托克顿,英国萨里。 ?@merlyn.demon.co.uk Turnpike v4.00 IE 4?

< URL:http://www.jibbering.com/faq/> JL / RC:新闻常见问题:comp.lang.javascript

< URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr数学,日期,来源。

< URL:http://www.merlyn.demon.co.uk/> TP / BP / Delphi / jscr /& c,FAQ项目,链接。


John Stockton博士写道:

JRS:在文章< ; 42 ********************* @ news.wanadoo.fr>,日期为星期二,
2005年7月19日03:59:12,在新闻中看到:comp.lang.javascript,ASM< stephanemo
ri ********* **@wanadoo.fr >发表:

grandTotal + =(what.elements [''price''+ i] .value - 0)*
(what.elements [''quantity'' + i] .value - 0);

乘法之前不需要显式地将String转换为数字。




谁可以做更多可以做得更少:-)

quantTotal + = what.elements [''quantity''+ i] .value * 1;



无需乘以1即可将String转换为Number;一元吧+
更优雅。




不明白什么是一元+?


foo = foo * 1

foo = foo + 0



foo = Number(foo);


看到任何比其他更好(或优雅)

见常见问题。




如果我找回它
< blockquote class =post_quotes>

subtotal = roundoff(Math.round(subtotal * Math.pow(10,2))/ Math.pow(10,2));
什么.grandTotal.value =
舍入(Math.round(grandTotal * Math.pow(10,2))/ Math.pow(10,2));



Math .pow(10,2)总是* 100;没有必要每隔一次计算一次,甚至一次。并且没有定义舍入。




我确实认为这不是我的代码被剥夺了...

并认为这是一个黑客

如果是着名的JS轮数= 9.000000000002

-

Stephane Moriaux et son [moins] vieux Mac

I have a form at http://www.develop.check.com.au/hh/order.html where
an extended sub-total and then a grand total is calculated as soon as
a quantity is input by a user. I would like to be able to add the
shipping cost to that grand total.

Shipping costs are in the "Postage & handling charges" link and are a
cost per box. If somebody selects "USA, Canada, Middle East" from the
drop down box it should recalculate the shipping cost, otherwise it
should calculate on the default - Australia.

If I post the calculation functions here they''ll wrap but they are at
http://www.develop.check.com.au/hh/calculate2.js

Many TIA for your help.

解决方案

Howard Martin wrote:

I have a form at http://www.develop.check.com.au/hh/order.html where
an extended sub-total and then a grand total is calculated as soon as
a quantity is input by a user. I would like to be able to add the
shipping cost to that grand total.

Shipping costs are in the "Postage & handling charges" link and are a
cost per box. If somebody selects "USA, Canada, Middle East" from the
drop down box it should recalculate the shipping cost, otherwise it
should calculate on the default - Australia.
calculation in caculate2.js :

shipping = new Array(''5.00'',''7.50'',''8.50'',''9.50'');

function total(what,number) {
var grandTotal = 0;
var quantTotal = 0;
for (var i=0;i<number;i++) {
if (what.elements[''price'' + i].value == '''')
what.elements[''price'' + i].value = ''0.00''; // fix for Opera.

what.elements[''subtotal'' + i].value=(what.elements[''quantity'' + i].value
- 0) * (what.elements[''price'' + i].value - 0);
if (what.elements[''quantity'' + i].value == "0")
what.elements[''subtotal'' + i].value = "0.00";

subtotal=what.elements[''subtotal'' + i].value
grandTotal += (what.elements[''price'' + i].value - 0) *
(what.elements[''quantity'' + i].value - 0);

quantTotal += what.elements[''quantity''+i].value*1;
}

shippingCost = quantTotal *
shipping[what.elements[''location''].selectedIndex];

shippingCost = quantTotal>200? shippingCost*0.8 :
quantTotal>100? shippingCost*0.9 :
quantTotal>50? shippingCost*0.95 :
shippingCost*1;
grandTotal += shippingCost;

subtotal = roundoff(Math.round(subtotal*Math.pow(10,2))/Math.pow(10,2));
what.grandTotal.value =
roundoff(Math.round(grandTotal*Math.pow(10,2))/Math.pow(10,2));

}
If I post the calculation functions here they''ll wrap but they are at
http://www.develop.check.com.au/hh/calculate2.js



calculation here :

shipping = new Array(''5.00'',''7.50'',''8.50'',''9.50'');

function total2(what) {
var quantTotal = 0;
var j=0;
for(var i=0;i<what.length;i++)
if(what.elements[i].name.substring(0,4)==''quant'')
j++;
for (var i=0;i<j;i++)
quantTotal += what.elements[''quantity''+i].value*1;
shippingCost = quantTotal *
shipping[what.elements[''location''].selectedIndex];
shippingCost = quantTotal>200? shippingCost*0.8 :
quantTotal>100? shippingCost*0.9 :
quantTotal>50? shippingCost*0.95 :
shippingCost*1;
what.grandTotal.value += shippingCost;
what.grandTotal.value=roundoff(Math.round(what.gra ndTotal.value*Math.pow(10,2))/Math.pow(10,2));
}
--
Stephane Moriaux et son [moins] vieux Mac


JRS: In article <42*********************@news.wanadoo.fr>, dated Tue,
19 Jul 2005 03:59:12, seen in news:comp.lang.javascript, ASM <stephanemo
ri***********@wanadoo.fr> posted :

Howard Martin wrote:

I have a form at http://www.develop.check.com.au/hh/order.html where

calculation in caculate2.js : grandTotal += (what.elements[''price'' + i].value - 0) *
(what.elements[''quantity'' + i].value - 0);
There is no need to explicitly convert String to Number before
multiplication.

quantTotal += what.elements[''quantity''+i].value*1;
There is no need to multiply by 1 to convert String to Number; a unary +
does it more elegantly.
See FAQ.

subtotal = roundoff(Math.round(subtotal*Math.pow(10,2))/Math.pow(10,2));
what.grandTotal.value =
roundoff(Math.round(grandTotal*Math.pow(10,2))/Math.pow(10,2));



Math.pow(10, 2) is *always* 100; there is no need to calculate it every
time, or even once. And roundoff is not defined.

--
? John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ?
<URL:http://www.jibbering.com/faq/> JL/RC: FAQ of 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.


Dr John Stockton wrote:

JRS: In article <42*********************@news.wanadoo.fr>, dated Tue,
19 Jul 2005 03:59:12, seen in news:comp.lang.javascript, ASM <stephanemo
ri***********@wanadoo.fr> posted :

grandTotal += (what.elements[''price'' + i].value - 0) *
(what.elements[''quantity'' + i].value - 0);
There is no need to explicitly convert String to Number before
multiplication.



who can do more can do less :-)

quantTotal += what.elements[''quantity''+i].value*1;


There is no need to multiply by 1 to convert String to Number; a unary +
does it more elegantly.



not understood what is a unary + ?

foo = foo*1
foo = foo+0
or
foo = Number(foo);

see any really better (or elegant) than other one
See FAQ.



if I find it back

subtotal = roundoff(Math.round(subtotal*Math.pow(10,2))/Math.pow(10,2));
what.grandTotal.value =
roundoff(Math.round(grandTotal*Math.pow(10,2))/Math.pow(10,2));


Math.pow(10, 2) is *always* 100; there is no need to calculate it every
time, or even once. And roundoff is not defined.



I did think this not mine code was debuged ...
and thought it was a hack
in case of famous JS round number = 9.000000000002

--
Stephane Moriaux et son [moins] vieux Mac


这篇关于计算表格中的运费的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆