[BASIC] STR$() odd question

Door sergarbes

Expert (114)

afbeelding van sergarbes

29-03-2022, 17:33

Hi all!

I'm going to ask an odd question about BASIC STR$() function. Why It returns one space character from the left, plus the conversion, having to subtract 1 when you want to LEN() the result of STR$()

Thanks in advance!

Smile Smile Smile

Aangemeld of registreer om reacties te plaatsen

Van Briqunullus

Hero (525)

afbeelding van Briqunullus

29-03-2022, 18:37

I've always thought the space character is reserved for the minus sign when converting negative values.

Van Parn

Paladin (791)

afbeelding van Parn

30-03-2022, 02:11

As Briqunullus said. If it's a negative value, then the first character will be a minus (character 45). Otherwise, it will always be a space (character 32).

Van sergarbes

Expert (114)

afbeelding van sergarbes

30-03-2022, 09:34

Cool, I didn't thought about it. You are both right. I have just tested it! I am in the process of relearning BASIC for fun and trying to develop a game is the final objective. Thank you for your answers!

Wink Wink Wink