Mark wrote:
I have a Decimal or a Double - your choice. I'd like to print the number as
string with a specified number of decimal places. Let's say my number
110.5, and I'd like to capture it in a string with 3 decimal places:
"110.500". How do you do this? My method below isn't working so hot.
Decimal dcTotal = 110.5;
string strMyString = (Decimal.Round(dcTotal, 3)).ToString();
//Do something with this string
dcTotal.ToString("0.000")
To be honest, I find it difficult to locate this information in the docs
- it takes a bit of digging past relatively useless stuff about
NumberFormatInfo and CultureInfo classes to get to the basic, predefined
format characters I want.
This information happens to be in the docs under the heading "Custom
Numeric Format Strings".
Note to MS: please put links to the standard and custom formatting
characters for the numeric and DataTime types in the document pages for
ToString() and String.Format().
--
mikeb