floating point

Andromeda

New Member
To whom it may concern,
I am trying to translate a measurement of inches to feet and inches. For instance if I am trying to convert 71 inches, it will be 5 feet 11 inches.

Let W0 = 71
W1 = W0 / 12 ‘ (This operation would give only the integer of the division, 5)
W2 = W0 // 12 *12 ‘ ( This operation gives as result 11 inches: 0.97 decimals multiplied by 12)

Nevertheless, when I try to do this arithmetic operation with the Picaxe 28X1, I get a lot of error, some times I get 5 feet 10 inches, some times 6 feet 0 inches. The microprocessor does not allow making simple operation just like a calculator where I just divide and get decimals multiply and so fort. Do you have any trick how to do this type of operations?
Thanks in advance
 

BeanieBots

Moderator
You can't do floating point but you can move the fixed point.

Multiply by 100 first. then break it down into the integer part and decimal part.

w0=71*100/12 'your number (71) multiplied by 100 then divided by 12.

b2=w0/100 'gives the integer part (should be 5 but the simulator makes it 6, this is a known bug)

b3=w0//100 'should be the decimal remainder which is 91
 

hippy

Ex-Staff (retired)
To convert (w0) inches to (w1) feet and (w2) inches ...

w0 = 71
w1 = w0 / 12
w2 = w0 // 12

/ gives the whole number of 12's divided into 71 ( 5 )
// gives the remainer ( 11 )

Not sure why you are seeing the occassional 6' 0" - are you running the simulator or using a physical PICAXE ?
 

westaust55

Moderator
While BB and hippy have given you some feedback, please note that you have posted in the:
PICAXE Forum > Finished User PICAXE Projects > Code Snippets
area and not the active forum area.

While you will get some responses, it is far better to post questions and problems in the active forum area where far more members look regularly.
 
Top