1

I was trying to align doubles using string.format and display them on a tooltip.

I used: string.Format("{0,15:N2}", number);

but the results come out as:

   1234.56
    00.00

It seems some of the numbers are narrower than the space. Does anyone know how to solve this problem?

Thanks!

1 Answer 1

4

Use a fixed-width font such as Courier New or Consolas if you want all the individual digits to line up.

1
  • No – numbers line up just fine in most fonts because they’re all the same width (new style figures). The problem is getting the decimal points below each other which isn’t possible using only string formatting. Dec 2, 2009 at 22:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.