Divide problem
marcla
Posts: 19
Hi!
When i divide 7845 with 36 i got 217 instead of 217,9166667 why??
I do like this:
and then i display time
When i divide 7845 with 36 i got 217 instead of 217,9166667 why??
I do like this:
VAR long Time Pub start Time := 7845/36
and then i display time
Comments
-Martin
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
SelmaWare Solutions - StampPlot GUI for controllers, XBee and Propeller Application Boards
Southern Illinois University Carbondale, Electronic Systems Technologies
American Technical Educator's Assoc. Conference·- April, Biloxi, MS. -- PROPELLER WORKSHOP!
Wouldn't you want to make "val" a double or float (whichever fp.div returns)? Also some compilers require a decimal point for floating constants (e.g. 7856.0,36.0) or else they interpret the numbers as integers. Is spin this way as well or is it smart enough to know you mean floating point?
Spin isn't smart enough to know anything, it doesn't care what's in a long variable or what that may mean to the programmer, just that it is a 32-bit value. It's up to the programmer to later use that variable in a context which makes sense.
You might also do the problem in integer math.
or, an alternative method that can kick out as many digits as you want...
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tracy Allen
www.emesystems.com
God catch, yes, the 36.0 and such is needed. since I answered initially, I felt obligated to follow-up, but didn't have time for a fully checked test. Sorry for the confusion.
-Martin