The following code currently outputs:
12.1
12.100
12.1000
12.00
12
12.0000
How can I change it so it outputs:
12.1
12.1
12.1
12
12
12
Math.Round seems to be the thing, but it makes me define how many decimal places I want, but I want them to be variable as above.
If there is no mathematical way to do it, I'll just strip the zeros and decimal points off the right side of the strings, but would think there is a math way to handle this.
using System;
using System.Collections.Generic;
namespace Test8834234
{
public class Program
{
static void Main(string[] args)
{
List<string> decimalsAsStrings = new List<string>
{
"12.1",
"12.100",
"12.1000",
"12.00",
"12",
"12.0000"
};
foreach (var decimalAsString in decimalsAsStrings)
{
decimal dec = decimal.Parse(decimalAsString);
Console.WriteLine(dec);
}
Console.ReadLine();
}
}
}