I'm learning qb64. I have a class problem where I have to print in columns with headings and for dollar-valued fields I have to align the columns by decimal. The chapter covers PRINT USING and I assumed that I was supposed to use that. I assumed that PRINT USING was like a formatted print in other languages; e.g., printf "%02d %12.4f", d, x; would print an integer in two columns, skip a column, and print a float using 12 columns with four decimals. The examples in the chapter suggest this interpretation for PRINT USING and I expect PRINT USING "## #######.####"; d; x to do about the same thing.
But in my program, the numbers don't seem to print formatted. Here's the code to print column headers:
Code: Select all
C$ = " \ \ \ \ \ \ \ \ \ \"
Print using C$; "beginning"; "ending"; "cost of"; "average"; " "
Print using C$; "inventory"; "inventory"; "goods sold"; "inventory"; "turnover"
and here's the code to print the numerical values:
Code: Select all
N$ = " #########,.## #########,.## $#########,.## #########,.# #########,.#"
Print using N$; beginv; endinv; cogs; avginv; turnover
In the output (see below), the column headers seem to be aligned using C$ abut the numbers are not similarly aligned using N$. Am I misunderstanding how PRINT USING works? Is there a better way to align numerical column by decimal place?
- output showing incorrect formatting
- Capture.JPG (26.58 KiB) Viewed 7823 times
When I look at the output, it seems like the literal spaces in N$ are being printed but the numbers are not being forced into the required fields. Is that not the correct interpretation of PRINT USING?
Also, the book uses a format like "###,###,###.##" but the qb64 wiki suggests "#########,.##" Is that the same? And is that fourteen columns? Or 13 columns? Or?