Software > Software

expressing a decimal in PBASIC

(1/4) > >>

555 timer chip guy:
I am trying to control a servo with a BS1 microcontroller but I can't figure out how to express the value 1.5 or any other decimals for that mater dose any one know how to express a decimal in PBASIC.

whats your code look like so far?

look into 'float', which is a variable type for storing decimal numbers. its been almost a decade since i programmed in PBASIC, but i dont remember ever having a problem with decimals when using them . . . in theory it should just work . . .

Somchaya:
I've never worked with PBASIC, but one way you could consider would be to use fixed-point math.

For example, you can store numbers like 1.5 and 2.4 as 15 and 24 respectively. This way, you can do
regular math on these "integers", and to get the digits and decimal parts, you can divide by 10 and mod by 10 respectively. Of course, if you needed more precision, you could use larger numbers like 100 or 1000, but you get the idea.

Hope this helps!

nanob0t:
A 'float' character stores decimals.  I don't know what it looks like in PBASIC though.

If anything, think of it a different way.  1.5  is also 3/2    Sometimes it can be a matter of modifying what you learned.  If you do division, make sure you store it in an appropriate integer.

Hope this helps

555 timer chip guy:
thanks very much for the help that  helped a lot . :D