Author Topic: String and Numbers with different alignment  (Read 1569 times)

0 Members and 1 Guest are viewing this topic.

Offline acjacques

  • Newbie
  • Posts: 33
String and Numbers with different alignment
« 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
« Last Edit: October 20, 2019, 08:56:10 pm by acjacques »

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • Steve’s QB64 Archive Forum
Re: String and Numbers with different alignment
« Reply #1 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”
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline acjacques

  • Newbie
  • Posts: 33
Re: String and Numbers with different alignment
« Reply #2 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

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
Re: String and Numbers with different alignment
« Reply #3 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!