Page 1 of 1

STR$ Function missing leading spaces

Posted: Fri Nov 24, 2023 12:06 pm
by jpd8266
Hi,
I am trying to align data on various display ( LCD 4x20 I2C, OLED Display, etc), using the STR$ function as per the example in Annex Help.
(Firmware Annex32 CAN 1.51.5 LFS on ESP32)

Code: [Local Link Removed for Guests]

''Test STR$Function as per Annex Help
'Missing leading spaces when using %x format

  a=12.34567890
  wlog "Value=";STR$(a,"%2.4f") 'should print Value=12.3457, - (note also the rounding on decimals)
  wlog "Value=";STR$(a,"%3.5f") 'should print Value= 12.34568
The number after the % sign parameter has no effect of the output.
Where is the problem ?

Thank you for your advices,
JP

Re: STR$ Function missing leading spaces

Posted: Fri Nov 24, 2023 1:01 pm
by cicciocb
Honestly I don't clearly understand your question.
Can you rephrase again ?

Probably what you say : "The X parameter has no effect of the output." means that you want show the number in hex format ?

If this is your question, probably you must do the following

Code: [Local Link Removed for Guests]

a = 129
wlog STR$(a, "%04x", 1)  ' if you want leading zeros '0'
wlog STR$(a, "%4x", 1)  ' if you want leading spaces

Re: STR$ Function missing leading spaces

Posted: Fri Nov 24, 2023 1:13 pm
by jpd8266
Sorry, my mistake :oops: :oops: : I will edit my original post, and will get new eyeglasses!

I meant the number after the % sign:

%2.4f to get 2 digits before decimal point
%3.4f to get 3 digits (or space) before the decimal point.

All this to vertically align values on a multilines display.

Re: STR$ Function missing leading spaces

Posted: Fri Nov 24, 2023 1:58 pm
by cicciocb
Yes, you are right, there is an error in the help file

The correct code is the following :

Code: [Local Link Removed for Guests]

a=12.34567890
wlog STR$(a, "%7.4f")
wlog STR$(a, "%9.5f")
In fact, the first number (i.e. 7 in %7.4f) represents the total number of characters to print, including the decimal point.
I''m going to update the help file.

You can find this information on the printf "c" function on internet.

Re: STR$ Function missing leading spaces

Posted: Fri Nov 24, 2023 2:09 pm
by jpd8266
Thank you ciccocb,

It works fine !
JP