If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > Oracle > simple mathematic calculation

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 01-21-06, 09:07
shatishr shatishr is offline
Registered User
 
Join Date: Aug 2005
Location: Kuala Lumpur, MY
Posts: 108
simple mathematic calculation

hie all

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 ?
Reply With Quote
  #2 (permalink)  
Old 01-21-06, 10:59
andrewst andrewst is offline
Moderator.
 
Join Date: Sep 2002
Location: UK
Posts: 5,171
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.
__________________
Tony Andrews
http://tinyurl.com/tonyandrews
Reply With Quote
  #3 (permalink)  
Old 01-21-06, 11:07
WilliamR WilliamR is offline
Registered User
 
Join Date: Sep 2004
Location: London, UK
Posts: 564
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:

Code:
/Users/williamr: float nm1=54
/Users/williamr: float nm2=62
/Users/williamr: echo $(( nm2-nm1/nm1 ))
61
/Users/williamr: echo $(( (nm2-nm1)/nm2 ))
0.129032258065
Update: Tony beat me to it.

I've just noticed that your formula varies:

Quote:
Originally Posted by shatishr
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
If nm1=54 and nm2=62, shouldn't that be (62-54)/54?

Code:
/Users/williamr: echo $(( (nm2-nm1)/nm1 ))
0.148148148148

Last edited by WilliamR; 01-21-06 at 11:27.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On