The following code currently outputs:
public class Program
static void Main(string args)
List<string> decimalsAsStrings = new List<string>
foreach (var decimalAsString in decimalsAsStrings)
decimal dec = decimal.Parse(decimalAsString);
You can also use decimal's ToString with a parameter:
string s = dec.ToString("0.#");
Note: You may have an internationalization issue with your code. The way you have coded it, it will use the culture info from the user's computer, which may have something other than
. for the decimal separator. This might cause your program to give incorrect results for users that have
. for thousands separator.
If you want to guarantee that the parse method will always behave the same, you could use CultureInfo.InvariantCulture. If you do actually want to parse the string according to the user's culture settings, what you are doing is fine.