The Double class's ToString method formats a Double value. For example, the following code displays a value as currency with a thousands separator and three digits after the decimal place.
Debug.WriteLine(value.ToString("$#,#.000"))
The following example displays positive values as currency values, negative values in parentheses, and zero as the string Zero.
Debug.WriteLine(value.ToString("$#,#.#;($#,#.#);Zero"))
This example program lets you enter values and enter or pick format strings to see the results. When you change the value or format string, the ShowValue routine displays the result. It simply converts the value into a Double and passes its ToString method the format string.
|