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

[manual] FORMAT$ %F length documentation is wrong.

Root / SmileBASIC Bug Reports / [.]

12Me21Created:
original postIf you do PRINT FORMAT$("%2.1F",10/3), you'd expect to see " 3.3", but it actually just prints "3.3", ignoring the 2. Similarly, PRINT FORMAT$("%02.1F",10/3) prints "3.3" instead of "03.3", and PRINT FORMAT$("% 2.1F",10/3) just prints " 3.3", which seems correct, until you try it with a 2 digit number and get " 10.3" (It just adds a leading space)
The %F format code generates floating point numbers. The manual says that you can specify the length of the parts before and after the decimal. For example, %3.3F should display 3 digits before the decimal place, and 3 after. However the first argument is actually the TOTAL length, so the previous example must be written as %7.3F.

It appears the number between % and . is not ignored, but it's not what the documentation says it should be, either. It is a minimum width, in characters, of the output. So, FORMAT$("%7.2F",10/3) gives " 3.33" (three leading spaces to bring the total number of characters up to 7).

Ah, ok. I wonder if this is a bug in SB, or just a mistake in the manual. I also found another similar mistake. If you put a space between the % and the number, it just inserts that space into the result. In the manual it says to put a space there to tell it to insert spaces (rather than 0s) before the number, but actually it just does that by default. EDIT: I'm pretty sure this is intentional, and the manual is incorrect, since this is how printf() does it.