var sidebar_align = 'right';
var content_container_margin = parseInt('290px');
var sidebar_width = parseInt('270px');
Unanswered: simple mathematic calculation
i created a test table and inserted '54' into nm1 column and '62' into nm2 column
i wanted to do a calculation which is 'nm2-nm1/nm1' in other words (62-54)/62 which should return 0.12
but its returning some other result...
any help ?
What result did you get? Not 61 by any chance?
If you look carefully at your calculation you will see it is actually 62-54/54, which is evaluated as 62-(54/54) which is 61.
nm2-nm1/nm1 is not the same as (62-54)/62! Check the rules for arithmetic precedence.
This will be the same in other languages, for example (just for fun) in Korn shell:
Update: Tony beat me to it.
/Users/williamr: float nm1=54
/Users/williamr: float nm2=62
/Users/williamr: echo $(( nm2-nm1/nm1 ))
/Users/williamr: echo $(( (nm2-nm1)/nm2 ))
I've just noticed that your formula varies:
If nm1=54 and nm2=62, shouldn't that be (62-54)/54?
Originally Posted by shatishr
/Users/williamr: echo $(( (nm2-nm1)/nm1 ))
Last edited by WilliamR; 01-21-06 at 11:27.