LoginLogin
Nintendo shutting down 3DS + Wii U online services, see our post

[manual] FORMAT$ space padding documentation is incorrect.

Root / SmileBASIC Bug Reports / [.]

TheV360Created:
I do this:
PRINT "*";FORMAT$("%03",999);"*"
and it shows this: (*s added to show beginning and end of string)
*999*
But if I do this:
PRINT "*";FORMAT$("% 3D",999);"*"
then this shows up:
* 999*
What is going on? Edit: Fixed % 3, 3DS keyboards are small

I do this:
PRINT "*";FORMAT$("%03",999);"*"
and it shows this: (*s added to show beginning and end of string)
*999*
But if I do this:
PRINT "*";FORMAT$("% 3",999);"*"
then this shows up:
* 999*
What is going on?
You typoed. In the second example it should be % 3D and the first example should be %03D. It looks as though when trying to use space padding, it will always expand to the number of digits + 1 space if the size of the number is less or equal to the number you specified, even though it's supposed to just expand to fit the number. Weirldy enough %4D and % 4D do exactly the same thing. I've always used the former, but I recall it putting the spaces AFTER the number as opposed to the space padding (I didn't even know the space padding format existed.) Did FORMAT$ get really screwed up in 3.3.0 or am I just remembering wrong?

No, I am just remembering wrong and SB puts the spaces before regardless of whether you space pad or not. I just get the weirdest feeling that's not how it's supposed to work. I'll have to try format strings in other langs. EDIT: What I am describing is common practice it seems, even with %4D and % 4D doing the same thing! I'm just being neurotic and seeing more bugs where they don't exist -_-

Putting a space in the format string doesn't add spaces before the value (the manual is wrong), it just adds a single space before positive numbers. This is how printf() works in other languages, so I'm pretty sure it's intentional and the manual is just wrong.