QB64.org Forum

Active Forums => QB64 Discussion => Topic started by: acjacques on October 20, 2019, 08:53:06 pm

Title: String and Numbers with different alignment
Post by: acjacques on October 20, 2019, 08:53:06 pm
What explain this?


x$ = "1234"
LOCATE 1, 10
PRINT "string="; x$
LOCATE 2, 10
mynumber = VAL(x$) 'string to number
PRINT "number="; mynumber 'I don't know why have one more space here when priting
Title: Re: String and Numbers with different alignment
Post by: SMcNeill on October 20, 2019, 09:18:20 pm
What explain this?


x$ = "1234"
LOCATE 1, 10
PRINT "string="; x$
LOCATE 2, 10
mynumber = VAL(x$) 'string to number
PRINT "number="; mynumber 'I don't know why have one more space here when priting

Placeholder for the sign. 

Think of how the values would line up if x$ was “-1234”
Title: Re: String and Numbers with different alignment
Post by: acjacques on October 20, 2019, 10:06:55 pm
OK. You are right. 

to check i have changed  the lines:

x$ = "-1234"

and

PRINT "number="; -mynumber
Title: Re: String and Numbers with different alignment
Post by: bplus on October 21, 2019, 01:11:24 am
Here is one from my toolbox for that PITA:
Code: QB64: [Select]
  1. FUNCTION ts$ (number)  'ts stands for trim string
  2.     ts$ = _TRIM$(STR$(number))
  3.  

no charge!