I align numbers with various number of decimals so that the decimal sign aligns on a straight row. This can be achevied by padding with spaces, but I'm having trouble.
Lays say I want to align the following numbers: 0 0.0002 0.531 2.42 12.5 123.0 123172
This is the result I'm after:
0
0.0002
0.531
2.42
12.5
123.0
123172
You can use string.format or ToString method of double to do so.
this article from msdn can help you if you need more details
If you want exactly that result you can't use any formatting of numerical data, as that would not format
123
as123.0
. You have to treat the values as strings to preserve the trailing zero.This gives you exactly the result that you asked for:
Output: