Integers print with leading space?

New to FreeBASIC? Post your questions here.
dkr
Posts: 34
Joined: Nov 20, 2015 15:17
Location: Alabama, USA

Integers print with leading space?

Postby dkr » Apr 05, 2019 15:27

Where o_ncards is dimensioned as an integer, the following code prints the line with a space between the comma (c) and the integer??
I know I can use print using, but why the leading space?

Code: Select all

c = ","
print #out_f, "NUM_CARDS";c;o_ncards


Output:
NUM_CARDS, 5

Thanks,
Darren
deltarho[1859]
Posts: 1802
Joined: Jan 02, 2017 0:34
Location: UK

Re: Integers print with leading space?

Postby deltarho[1859] » Apr 05, 2019 15:46

We get a leading space with signed integers, but not unsigned integers.
paul doe
Posts: 916
Joined: Jul 25, 2017 17:22
Location: Argentina

Re: Integers print with leading space?

Postby paul doe » Apr 05, 2019 15:52

dkr wrote:...
I know I can use print using, but why the leading space?
...

Indeed, the leading space is for the sign. If you want to get rid of it (in case of positive integers), simply convert the number before printing (either with the & string contatenation operator or with the str() function:

Code: Select all

dim as integer _
  o_ncards => 5
dim as string _
  c => ","

? "NUM_CARDS"; c; o_ncards

? "NUM_CARDS"; c & o_ncards
? "NUM_CARDS"; c; str( o_ncards )

sleep()
dkr
Posts: 34
Joined: Nov 20, 2015 15:17
Location: Alabama, USA

Re: Integers print with leading space?

Postby dkr » Apr 05, 2019 16:01

Ok, great. I forgot about the sign

Thanks,
Darren

Return to “Beginners”

Who is online

Users browsing this forum: No registered users and 17 guests