![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
I'm using the formula: var ship=round((((total1/20)*2)+((total2/20)*2)+((total3/20)*2)+(((total6/20)*3) +2)+((total7/20)*2)),2) to calculate shipping charges, it works perfect. Now, I want to modify this formula so the minimum net result = 5 and the maximum = 30. So if the calculated value equals less than 5, the result will be 5. If exceeds 30, result will be 30. I have tried different IF , <, > test permutations without success. Any suggestions appreciated |
#3
| |||
| |||
|
|
"Edward" <nomail (AT) yahoo (DOT) com> kirjoitti viestissä:g2QQe.8923$Yh6.7258 (AT) fe04 (DOT) lga... I'm using the formula: var ship=round((((total1/20)*2)+((total2/20)*2)+((total3/20)*2)+(((total6/20)*3) +2)+((total7/20)*2)),2) to calculate shipping charges, it works perfect. Now, I want to modify this formula so the minimum net result = 5 and the maximum = 30. So if the calculated value equals less than 5, the result will be 5. If exceeds 30, result will be 30. I have tried different IF , <, > test permutations without success. Any suggestions appreciated if(ship<5) ship = 5; else if(ship>30) ship = 30; huh? -- SETI @ Home - Donate your cpu's idle time to science. Further reading at <http://setiweb.ssl.berkeley.edu/ Kimmo Laine <eternal.erectionN0 (AT) 5P4Mgmail (DOT) com |
#4
| |||
| |||
|
|
"Edward" <nomail (AT) yahoo (DOT) com> kirjoitti viestissä:g2QQe.8923$Yh6.7258 (AT) fe04 (DOT) lga... I'm using the formula: var ship=round((((total1/20)*2)+((total2/20)*2)+((total3/20)*2)+(((total6/20)*3) +2)+((total7/20)*2)),2) to calculate shipping charges, it works perfect. Now, I want to modify this formula so the minimum net result = 5 and the maximum = 30. So if the calculated value equals less than 5, the result will be 5. If exceeds 30, result will be 30. I have tried different IF , <, > test permutations without success. Any suggestions appreciated if(ship<5) ship = 5; else if(ship>30) ship = 30; huh? -- SETI @ Home - Donate your cpu's idle time to science. Further reading at <http://setiweb.ssl.berkeley.edu/ Kimmo Laine <eternal.erectionN0 (AT) 5P4Mgmail (DOT) com |
#5
| |||
| |||
|
|
I must have syntax problems. My below test looks good, but doesn't work. var ship_amt= round((((total1/20)*2)+((total2/20)*2)+((total3/20)*2)+(((total6/20)*3)+2)+( (total7/20)*2)),2) var ship IF(ship_amt<5) ship=5 else if(ship_amt>30) ship=30 else ship=ship_amt |
#6
| |||
| |||
|
|
"Edward" <nomail (AT) yahoo (DOT) com> kirjoitti viestissä:%2_Qe.17075$ih4.15235 (AT) fe02 (DOT) lga... I must have syntax problems. My below test looks good, but doesn't work. var ship_amt= round((((total1/20)*2)+((total2/20)*2)+((total3/20)*2)+(((total6/20)*3)+2)+( (total7/20)*2)),2) var ship IF(ship_amt<5) ship=5 else if(ship_amt>30) ship=30 else ship=ship_amt Naturally the IF should be in lowercase, ie. if, but I assume that's just a typo. You might try debugging it with alerts. So let's modify the code a bit. var ship_amt= round((((total1/20)*2)+((total2/20)*2)+((total3/20)*2)+(((total6/20)*3)+2)+( (total7/20)*2)),2) alert( "1: " + ship_amt ); var ship if( ship_amt < 5 ){ ship = 5; alert("2: amount less than 5. " + ship); } else if( ship_amt > 30 ) { ship = 30; alert( "3: amount more than 30. " + ship ); } else ship = ship_amt; alert( "4: amount between 5 and 30. " + ship ); } See which alerts are triggered... Out of curiosity: what does the round function do? Since it's not the javascript native Math.round, does it come from your own function library? I assume it has enhanced functionality in rounding to certain decimal, since your giving it a second parameter which would seem like the precision to me... -- SETI @ Home - Donate your cpu's idle time to science. Further reading at <http://setiweb.ssl.berkeley.edu/ Kimmo Laine <eternal.erectionN0 (AT) 5P4Mgmail (DOT) com |
#7
| ||||||
| ||||||
|
|
Ok its working like this: var ship_amt=round((((total1/20)*2)+((total2/20)*2)+((total3/20)*2)+(((total6/20 )*2)+2)+((total7/20)*2)),2) var ship if(ship_amt < 5) ship = 5; else if(ship_amt > 30) ship = 30; else ship = ship_amt; |
|
It didn't like the Alerts. |
|
Are the semi-colons important? |
|
I was using lower case "if" in my tests. |
|
function round(number,X) {return Math.round(number*Math.pow(10,X))/Math.pow(10,X)} |

|
Used with 2 assures two decimal place Cents, very important to PayPal submission I hear(my next hurdle). |
#8
| |||
| |||
|
|
I'm using the formula: var ship=round((((total1/20)*2)+((total2/20)*2)+((total3/20)*2)+(((total6/20)*3) +2)+((total7/20)*2)),2) to calculate shipping charges, it works perfect. Now, I want to modify this formula so the minimum net result = 5 and the maximum = 30. So if the calculated value equals less than 5, the result will be 5. If exceeds 30, result will be 30. |
ship>30)?30:ship;|
I have tried different IF , <, > test permutations without success. |
|
Any suggestions appreciated |
![]() |
| Thread Tools | |
| Display Modes | |
| |