unsigned longs and doubles - quick question

I have a variable (called delay) that is currently "unsigned long". It's from the stepper motor library. i want to increase that variable in a loop as follows:

start loop:

delay = delay + 0.0054

back to top.

I am getting very funny outputs. I know (I think) that unsigned long will not handle the 0.0054 value so what should I do? Should i change delay into a "double" variable? But how many decimal places will that work for. The fact is that I know the delay will not "in fact" increase by a fraction of a millimeter, but I want the value to increment at that fraction.

Sorry, I know that this is an easy question, but not much help out there on this...



Hi Ben, the answer to your question depends on what you want to do with the delay variable. One approach is to multiply your values by 10000, so 0.0054 becomes 54, 1000 becomes 10000000. An unsigned long holds nine decimal digits so that would work for numbers between 100000 and 0.00001

But perhaps if you say a little more about what your sketch will do with these values, we can give you some more help.