Pregunta

I am trying to format a double that represents a value from -12.00V to 12.00V.

I am having a hard time formatting it so that the string produces always has the decimal point in the middle.

The String.Format() arguments ("{0:0.00V}") I use produces 4 "types" of numbers

0.00V
00.00V
-0.00V
-00.00V

I would like a way to make all of the "types" appear like so

  0.00V
 00.00V
 -0.00V
-00.00V

So that all of the decimal places always line up with each other no matter the value. Is this possible with .Format()? I know there is the alignment argument but that just aligns the entire string to the left or right and not the string within its own "space".

¿Fue útil?

Solución

To right-align, add a width specifier:

"{0,8:0.00V}"

that will give you room for the V, two decimals, a decimal point, two significant digits to the left, a sign, and a leading space (or three significant digits and no leading space).

Otros consejos

Use the PadLeft function as follows: [YourStringVariable].PadLeft(6) (MSDN Link)

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top