QB64.org Forum

Active Forums => QB64 Discussion => Topic started by: hanness on February 19, 2020, 12:20:48 am

Title: Help needed with templates for PRINT USING
Post by: hanness 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.
Title: Re: Help needed with templates for PRINT USING
Post by: FellippeHeitor 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
Title: Re: Help needed with templates for PRINT USING
Post by: hanness on February 19, 2020, 03:29:20 am
That helps greatly. Thanks.