Author Topic: Help needed with templates for PRINT USING  (Read 2917 times)

0 Members and 1 Guest are viewing this topic.

Offline hanness

  • Forum Regular
  • Posts: 210
    • View Profile
Help needed with templates for PRINT USING
« on: February 19, 2020, 12:20:48 am »
I'm having a little difficulty figuring out the usage of templates for PRINT USING.

Assume I have this statement:

PRINT USING "####.##"; Value

This statement will print the variable Value with 4 characters before the decimal point and 2 characters after.

My goal is print Value with 2 positions after the decimal point but without any template affecting the integer portion to the left of the decimal point. In other words, with the example above, the program would always display 4 positions to the left of the decimal point even if it is a single digit number which means that there will be 3 extra spaces.

Is there any way around this? Is there any help on the format of templates that can be used for PRINT USING? If it is included in help, I simply missed it.

Marked as best answer by hanness on February 18, 2020, 10:29:32 pm

FellippeHeitor

  • Guest
Re: Help needed with templates for PRINT USING
« Reply #1 on: February 19, 2020, 12:28:14 am »
My goal is print Value with 2 positions after the decimal point but without any template affecting the integer portion to the left of the decimal point.

Spaces will be printed where no numbers fill the positions marked by #, it's by design. A hack around it, ugly as can be, could be written as:

Code: QB64: [Select]
  1. a! = 1.348
  2. PRINT _TRIM$(STR$(FIX(a!))); USING ".##"; (a! - FIX(a!))

Is there any help on the format of templates that can be used for PRINT USING? If it is included in help, I simply missed it.

http://www.qb64.org/wiki/PRINT_USING
« Last Edit: February 19, 2020, 04:40:25 am by FellippeHeitor »

Offline hanness

  • Forum Regular
  • Posts: 210
    • View Profile
Re: Help needed with templates for PRINT USING
« Reply #2 on: February 19, 2020, 03:29:20 am »
That helps greatly. Thanks.