String to num 1st Zero lost

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 8.

Moderator: Benj

Post Reply
viktor_au
Posts: 342
Joined: Fri Jan 26, 2018 12:30 pm
Location: South Australia
Has thanked: 44 times
Been thanked: 60 times
Contact:

String to num 1st Zero lost

Post by viktor_au »

Hello
I found some answer for question below
----------------------------------------------------------:
SteveM » Tue Jun 10, 2014
Loosing 1st zero during converstion of num to string
There's no way to do that directly, because the values are stored within the chip as fixed length binary numbers. e.g. if you store your number as a ULONG (4 bytes), it will always be 32bits long inside the chip. When you convert the String to an Integer, any leading zero's in the string will just be ignored, and the chip pads the number with enough 'binary zeros' to fill the bytes.
---------------------
Steve suggested to get the length of the string, however this is OK during the (back) num-to-string conversion.
-------------------
Question
How can I save to integer string "077" without loosing 1st Zero?
Thanks
Attachments
StringToNumZeroLost_1.fcfx
(11.58 KiB) Downloaded 101 times

chipfryer27
Valued Contributor
Valued Contributor
Posts: 662
Joined: Fri Jun 06, 2014 3:53 pm
Has thanked: 184 times
Been thanked: 203 times
Contact:

Re: String to num 1st Zero lost

Post by chipfryer27 »

Hi

Just heading out, sorry to be brief.

What about using Right$ in a calculation?

e.g.
x$ = 123045
y$=Right$(x$,3)

y$ would equal 045

Just a thought and might not be applicable in your scenario.

Regards

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: String to num 1st Zero lost

Post by medelec35 »

Hello.
Leading zeros can't be used for non-strings as they will be treated as octal i.e. to the base 8 rather than base 10
If you did enter a leading zero in an expression eg MyInt = 0123 then the actual value of MyInt will be decimal 83, which will not be what you are expecting.
The only way of displaying a leading zero is in a string format.
Martin

viktor_au
Posts: 342
Joined: Fri Jan 26, 2018 12:30 pm
Location: South Australia
Has thanked: 44 times
Been thanked: 60 times
Contact:

Re: String to num 1st Zero lost

Post by viktor_au »

What about using Right$ in a calculation?
-------------------------------------------------------
Sure... but I wanted the integer as 077.

The only way of displaying a leading zero is in a string format
Looks like I have to flag the converted integer 77 (from "077" string) as negative.

Thanks

Post Reply