My solution is padding with figure space (U+2007), its width is equal to the width of a digit:
label.Text = number.ToString("0.00").PadLeft(6,'\x2007');
質問
I have the following floating point numbers, all with 2 decimal places:
2.47
57.83
93.92
119.20
I want to output these numbers as follows:
2.47
57.83
93.92
119.20
How can I achieve that in C#, if the font is not monospaced?
Edit:
Or is there any invisible character that occupies the same amount of horizontal space as a digit?
解決 3
My solution is padding with figure space (U+2007), its width is equal to the width of a digit:
label.Text = number.ToString("0.00").PadLeft(6,'\x2007');
他のヒント
Try string.Format("{0,6:F2}", number)
.
I've never used Gtk#
before, but a quick Google search revealed this.
label.Justify = Justification.Right;
This is a much simpler and more reliable strategy than trying to manipulate the string to the proper width.