Page 1 of 1

I need to divide an Integer by 2048 and display as a decimal

Posted: Mon Jan 25, 2016 1:00 am
by Richard
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

Re: I need to divide an Integer by 2048 and display as a dec

Posted: Mon Jan 25, 2016 4:06 am
by Richard
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