As I understood it, if you did something in Kotlin like String.format("%3d", 4)
(arbitrary example put illustrates my point) you would get a string like " 3"
(padded to the left by two spaces). For some reason, when I do that in Kotlin, it is instead centering the string (so I get something like " 3 "
). Any clue why this could be happening? Everything I'm reading says right-aligned is the default, but that's not happening for me.
Example:
hp.text = String.format("%-10s%4d%-5s%4d%-5s%4d", "HP:", pokemon.hp, "EVs:", pokemon.hpEv, "IVs:", pokemon.hpIv)
For context, this info is read in from the output of a Lua script reading the memory of a Desmume emulator playing a Pokemon game. Basically this string is in 6 sections. First the name of the stat, then the stat itself. Followed by "EVs:" and the number of EVs for that stat, and "IVs:" and the number of IVs for that stat. For now, between left aligning the text (which does work for some bizarre reason) and putting tabs () between everything, I've gotten it look... acceptable. But what's happening here is that the numbers seem to be centered within their section of the string. Here's a picture of what this ends up looking like.
I would have expected the numbers to be right-aligned so that the 1s place in each of them lines up, but that's not happening for some reason.
UPDATE: I've also tried left-aligning everything by adding -
after all the percent signs and that makes all the numbers left-aligned with each other. It's just so baffling to me that I can't seem to get it to right-align for the life of me. Dragonite again, left-aligned this time
UPDATE 2: I figured it out, put my answer down below. A key point that I didn't realize when I posted this (I adopted this codebase, didn't create it from scratch), was that it was using tornadofx, possibly with a default non-monospaced font.
question from:https://stackoverflow.com/questions/66057180/kotlin-string-format-is-centering-my-text