Hi,
I am sampling an accelerometer and placing the result in an integer (AccelMax).
The accelerometer represents 0 G's as 0 counts, and 16 G's as 32767 (2048 counts per G)
If I just divide the integer (AccelMax) by 2048, it rounds it off down to the nearest whole integer. I need to be able to show at least 2 decimal places. I'm not sure where to go from here. Any help is appreciated. Thanks.
Richard
I need to divide an Integer by 2048 and display as a decimal
Moderator: Benj
-
- Posts: 9
- Joined: Sun Jan 10, 2016 7:18 pm
- Has thanked: 2 times
- Been thanked: 4 times
- Contact:
Re: I need to divide an Integer by 2048 and display as a dec
I figured out how to do it, only using integers.
I created 3 loops, one to figure out the whole number, passed on the remainder, one for the tenths, passed on the remainder, and one for the hundredths. Once I figured it out, it is quite simple (what isn't), and can be used for any base number to be divided by, and any number of decimal places, just change the number you subtract, and add more loops.
I have included my program for others.
Richard
I created 3 loops, one to figure out the whole number, passed on the remainder, one for the tenths, passed on the remainder, and one for the hundredths. Once I figured it out, it is quite simple (what isn't), and can be used for any base number to be divided by, and any number of decimal places, just change the number you subtract, and add more loops.
I have included my program for others.
Richard
- Attachments
-
- Convert Integer to Decimal Number.fcfx
- (8.91 KiB) Downloaded 197 times