I need to read and store signed floating point ASCII (-xx.x)

Hello,

I need to store floating point ascii data * 10 in a sword variable, but REAL modifier work only for OUTPUT.

String format of sensor is XXX.X can be :

String = “18.7” I need store Var = 187
String = “0.4” I need store Var = 4
String = “-0.5” I need store Var = -5
String = “-36.0” I need store Var = -360

My code work only for POSITIVE value:(

'input is 10.5 serin pin, baud, [dec int, dec flo] output = int * 10 + flo 'output is 105, work.

I can’t test “int” because I lost sign for -0.xxxx

Edit: I use Atom Pro 28 + IDE 8.0.1.3

Please help me.
Pascal

Atom or Atom Pro…

Sorry
Pro 28, I use 8.0.1.3 beta.

Pascal

I know this is an older post but I wanted to give an answer for those who may need it in the future.

Use “sdec” instead of “dec” to read in signed values via serin.

sdec cannot read signed negative value…
How to ?

DEC is for UNSIGNED values
SDEC if for signed values.

Ie. DEC will ignorethe “-” character.

If you send a “-123” DEC will only see “123”.

SDEC sees “-” characters so if you send “-123” it will see “-123” and return a -123. Note you MUST use signed variables with sdec for it to work correctly.

For example, if you send a “-1” to SDEC but the variable for SDEC is a WORD(instead of an SWORD) your variable will hold 65535 instead of -1.