Autor | Zpráva | ||
---|---|---|---|
senior Profil |
#1 · Zasláno: 1. 1. 2008, 22:02:25
Zdravím vospolok.
Mám JS: function Total() { var tot = 0; tot += (15.00 * document.order.qty1.value); tot += (70.00 * document.order.qty2.value); tot += (50.00 * document.order.qty3.value); tot += (30.00 * document.order.qty4.value); tot += (70.00 * document.order.qty5.value); tot += (90.00 * document.order.qty6.value); tot += (70.00 * document.order.qty7.value); tot += (120.00 * document.order.qty8.value); tot += (50.00 * document.order.qty9.value); tot += (40.00 * document.order.qty10.value); tot += (70.00 * document.order.qty11.value); document.order.totalcost.value = tot; document.order.totalcost1.value = tot * 1.2; document.order.totalcost2.value = tot * document.order.noc.value; document.order.totalcost3.value = tot * 1.2 * document.order.noc.value; document.order.totalcost4.value = tot * document.order.noc.value * 0.5; document.order.totalcost5.value = tot * 1.2 * document.order.noc.value * 0.5; } // funkcia na update cien pri zmene function UpdateCost(number, unitcost) { costname = "cost" + number; qtyname = "qty" + number; var q = document.order[qtyname].value; document.order[costname].value = q * unitcost; Total(); } a potreboval by som v tejto časti document.order.totalcost1.value = tot * 1.2; document.order.totalcost2.value = tot * document.order.noc.value; document.order.totalcost3.value = tot * 1.2 * document.order.noc.value; document.order.totalcost4.value = tot * document.order.noc.value * 0.5; document.order.totalcost5.value = tot * 1.2 * document.order.noc.value * 0.5; urobiť zaokrúhlenie na celé číslo (sumu). Môže mi prosím niekto pomôcť? Ďakujem. |
||
DJ Miky Profil |
#2 · Zasláno: 1. 1. 2008, 22:20:01
Zaokrouhlení uděláš funkcí Math.floor(), zaoukrouhlení nahoru Math.ceil() a dolů Math.floor().
|
||
senior Profil |
#3 · Zasláno: 1. 1. 2008, 22:27:45
DJ Miky
Vďaka za radu, ale JS sa iba učím, takže si s tym moc neporadím :-( |
||
peta Profil |
#4 · Zasláno: 4. 1. 2008, 08:17:53
http://www.volny.cz/peter.mlich/www.htm#msub8
ceil, floor, round ... google.com javascript math round example var f,t; f = document.order; t = 0; t+= (15.00 * f.qty1.value); t+= (70.00 * f.qty2.value); t+= (50.00 * f.qty3.value); t+= (30.00 * f.qty4.value); t+= (70.00 * f.qty5.value); t+= (90.00 * f.qty6.value); t+= (70.00 * f.qty7.value); t+= (120.00 * f.qty8.value); t+= (50.00 * f.qty9.value); t+= (40.00 * f.qty10.value); t+= (70.00 * f.qty11.value); alert(Math.round(t*1.2)); pozorr, neco.value je typu string. Kdybys tam nemel to nasobeni, pak by s tim pracoval jako s retezcem. Scitani retezcu: '1'+'1' = '11' |
||
senior Profil |
#5 · Zasláno: 4. 1. 2008, 12:10:01
peta
Vďaka za pomoc. Idem to naštudovať a vyskúšať. |
||
peta Profil |
#6 · Zasláno: 4. 1. 2008, 19:00:06
senior
Mno, jako ale bacha na zaokrouhlovani, protoze u platebnich dokladu plati jakasi pravidla. U nekterych, ze se zaokrouhluje konecna cena a to jeste tak, ze ti musi souhlasit cena polozek pred zdanenim. Ku prikladu, kdyz v obchode koupis lizatko po 9.30 , cokoladu po 6.30, napocitas dane, tak se to zaokrouhluje v CZ na padesatnik tusim nahoru. Mno, ale nektere polozky se zaokrouhluji jeste pred sdanenim nebo podle skladu. Treba 10 hrebiku z jednoho skladu a 15 skobicek z jineho muze ochod rozepsat na 2 faktury a kazdou na padesatniky. A pak je treti moznost, co jsem psal, ze soucet + dan = zaokrouhleno musi to sedet zpetne bez zaokrouhleni zaokrouhleno = soucet + dan , tim padem zaokrouhleni jako takove tam jakoby neni, ikdyz se provadi |
||
senior Profil |
#7 · Zasláno: 5. 1. 2008, 18:13:42
peta
Vďaka za upozornenie, ale v mojom prípade ide o neplátcu DPH. Jedná sa o spočítanie položiek s prirážkou 20% pre určitú skupinu plátcov. Zatiaľ to skúšam prerobiť podľa Tvojho návodu. Dúfam, že bude všetko O.K. |
||
Časová prodleva: 16 let
|
0