How do you use Decimals
computer guy
Posts: 1,113
How do i set a VAR (variable) as a decimal. say 0.003 for example. On the BS2.
I tried VAR Word but it just comes up as 0
Thank you
I tried VAR Word but it just comes up as 0
Thank you
Comments
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tracy Allen
www.emesystems.com
This is the code that needs decimals.
I am doing this for a science fair project and need my results as a decimal. (I cant aford to get them wrong.)
Thank you
Post Edited (computer guy) : 4/4/2007 11:53:37 PM GMT
so can someone make a windows application for me to
1. read a number from the serial port. (this will be the speed in us).
2. get 10 copies of this number and average them.
3. divide the number by 1000
4. divide it by 1000 again. (to get the number into seconds).
5. divide 1 by the number. (to get the speed in m/s).
Thank you
time = rawDist / 1000 'convert to ms
Instead of thinking of it as ms, think of it as 1000ths of a second. Then your only trick is displaying it with the decimal point in the right place, e.g.
434 ms = .434 seconds
1356 ms = 1.356 seconds (although you won't get ms that high from sonar, but hopefully you get the idea).
The same can be done with the raw distance, etc.
Really what you are looking to do is something like:
x = rawTimeinMs
DEBUG DEC1 x/1000, ".", DEC3 x//1000
Which would give you 1 place to the left of the decimal and 3 places to the right of the decimal.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
When the going gets weird, the weird turn pro. -- HST
Thank you
Thank you
You can do fixed point arithmetic using integers as described by representing perhaps 2 to 4 decimal places with an integer value, essentially by changing units. For example, instead of talking about fractional seconds, you keep your time information in milliseconds as an integer. As Zoot illustrated, you can format the information to display as seconds with 2 or 3 decimal places, but, in the Stamp, it's stored in a 16-bit word as an integer millisecond value.
The numbers i am working with are in the range of 334.333'
Thank you
Do have a look at Tracy Allen's website (www.emesystems.com) for lots of information on doing math with Stamps including multiple precision and fixed point.
Thank you
I usually divide 1m by how long it takes to travel.
now i have to use 2 */ time to get the correct result.
Could someone explain this please.
Thank you
i need to put 2 */ time in order to get the right number range.
In the debug window i get.
Thank you
So
My maths in the code i posted Today 10:16 AM (GMT -7) is obviously incorrect then.
Thank You