The following code is currently being displayed:
12.1 12.100 12.1000 12.00 12 12.0000
How can I change it so that it displays:
12.1 12.1 12.1 12 12 12
Math.Round seems to be a thing, but it forces me to determine how many decimal places I want, but I want them to be variables as above.
If there is no mathematical way to do this, I will simply delete the zeros and decimal points on the right side of the lines, but I think there is a mathematical 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(); } } }
decimal c # rounding
Edward Tanguay Jan 23 '10 at 12:40 2010-01-23 12:40
source share