wlog int(1234.5),str$(int(1234.5),"%5d"),str$(int(1234.5),"%5u")
Yields: 1234 0 0
How do I print an integer right-justified within a fixed number of characters?
(If it makes a difference, this is with a C3SuperMini.)
Also, the spacing in the documentation seems to imply that wlog "|"+str$(15,"%4.3f")+"|" would be printed with two spaces before the 15.000, but I get |15.000|.
Why does "%d" in str$ print zero?
-
- Posts: 195
- Joined: Mon Feb 08, 2021 10:10 pm
- Location: Scotland
- Has thanked: 92 times
- Been thanked: 77 times
Re: Why does "%d" in str$ print zero?
I think you need the additional ",!" for integers...
Code: [Local Link Removed for Guests]
wlog int(12345.6),str$(int(12345.6),"%5d",1),str$(int(1234.5),"%5u",1)
Re: Why does "%d" in str$ print zero?
That works, thanks, but I can't say I understand why it should be necessary, since "%d" and "%u" imply integers, and the int() should be converting the numbers to integers.[Local Link Removed for Guests] wrote: [Local Link Removed for Guests]Sat Jun 28, 2025 5:00 pmI think you need the additional ",!" for integers...
- cicciocb
- Site Admin
- Posts: 3254
- Joined: Mon Feb 03, 2020 1:15 pm
- Location: Toulouse
- Has thanked: 650 times
- Been thanked: 2290 times
- Contact:
Re: Why does "%d" in str$ print zero?
This is required because the internal printf() C-function need to know the format of the value to be converted (in annex all the variables are floating point)[Local Link Removed for Guests] wrote: [Local Link Removed for Guests]Sat Jun 28, 2025 11:26 pmThat works, thanks, but I can't say I understand why it should be necessary, since "%d" and "%u" imply integers, and the int() should be converting the numbers to integers.[Local Link Removed for Guests] wrote: [Local Link Removed for Guests]Sat Jun 28, 2025 5:00 pmI think you need the additional ",!" for integers...