Search code examples
c#floating-pointgtk#number-formatting

How to align floating point numbers in C# (left padding)


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?


Solution

  • 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');