1

On my UI, there are several textboxes that are vertically aligned. I'd like to show the numbers in them in a way that all floating points are also vertically aligned. I also need to show the sign of the numbers (+ and -). Here is an example of what I am trying to have:

- 123.123456
+   1.123456
-   0.123456
-   0.123
+   1.1
-  12.123456

I have been using this code (https://stackoverflow.com/a/27510646/3179989):

textbox1.Text = String.Format("{0:+;-}{0,9:0.00000;0.00000}", number1);
textbox2.Text = String.Format("{0:+;-}{0,9:0.00000;0.00000}", number2);
textbox3.Text = String.Format("{0:+;-}{0,9:0.00000;0.00000}", number3);
textbox4.Text = String.Format("{0:+;-}{0,9:0.00000;0.00000}", number4);
textbox5.Text = String.Format("{0:+;-}{0,9:0.00000;0.00000}", number5);

However, I recently realized that this method does not work for numbers below 0.5 (Issue with Formatting a double variable to show in textbox in C#).

Is there any solution that works for all numbers?

Thanks

Community
  • 1
  • 1
NESHOM
  • 899
  • 16
  • 46

0 Answers0