QB64.org Forum
Active Forums => QB64 Discussion => Topic started by: MarcoPajotter on April 23, 2021, 10:35:24 am
-
Hello,
And yes I have a new question,
I'm numbering a list, from 0 ... 100, and I like this line numbers as "0001" ... "0100" and not "1" ... "100"
Q) How can I fill the string with previous zero's in front of the "1" to show it as "0001"
I already did this:
LET MyNumberString
= "00000000"
But this is not showing the good result ...
Thanks,
Marco
-
-
Something like this?
numberstring$
= MID$(STR$(10000 + i
), 3) PRINT "'"; numberstring$;
"'"
Printed with quoutes to show there are no spaces in the strings.
-
Slight mod
DIM Digits AS INTEGER
DIM i AS _UNSIGNED LONG
Digits = 4
FOR i = 0 TO 10 ^ Digits - 1
numberstring$ = RIGHT$(STR$(10 ^ Digits + i), Digits)
PRINT "'"; numberstring$; "'"
NEXT i
Max digits = 6. If more than 6 digits, the output goes exponent notation ?
-
This one works better.
DIM Digits AS INTEGER
DIM i AS _UNSIGNED LONG
DIM Base10 AS _UNSIGNED LONG
Digits = 7
Base10 = 10
FOR i = 0 TO 10 ^ Digits - 1
numberstring$ = RIGHT$(STR$(Base10 ^ Digits + i), Digits)
PRINT "'"; numberstring$; "'"
NEXT i
-
Digits = 7
FOR i = 1 TO 100
numberstring$ = RIGHT$(“0000000000000000000000000” + _TRIM$(STR$(i)), Digits)
PRINT numberstring$
IF i MOD 20 = 0 THEN SLEEP
NEXT i
Good for as many digits as an _INTEGER64 can contain. Just change the value of Digits.
-
With _INTEGER64 the max digits is 18?
DIM i AS _INTEGER64
DIM Digits AS INTEGER
Digits = 18
FOR i = 0 TO 10 ^ Digits - 1
numberstring$ = RIGHT$(STRING$(Digits, "0") + _TRIM$(STR$(i)), Digits)
PRINT numberstring$
IF i MOD 20 = 0 THEN SLEEP
NEXT i
Hey that's a neat trick i MOD 20 = 0 !
-
Thanks everyone,
It works well, and I need some time now to make the good choice ...
And thanks for the quick responses.
Marco