I am trying to format a numeric value with leading spaces, to pack the string out to a given length, thus:-
mystring = mynumber.ToString ("format-string")
but am having no luck finding the correct format string. I have seen the question here and tried the answer suggested, but it doesn't work. For 123.4,
.ToString ("####.#") gets "123.4"
.ToString ("6:####.#") gets "6:123.4"
.ToString ("0,6:####.#") gets "06:0,123.4"
.ToString ("{####.#}") gets "{123.4}"
.ToString ("{6:####.#}") gets "{6:123.4}"
.ToString ("{0,6:####.#}") gets "{06:0,123.4}"
Is there anything I can try to get " 123.4"?
You can't use the ToString method for that format, you need to use the String.Format method:
String.Format("{0,6:####.#}", number)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With