Convert to two decimal places C# Round to 2 decimal places There are various methods or you can say ways available to round a number to two decimal places. When we store values in our database, Our main concern is to have a good precision so for that the numbers are stored with lots of decimal places. There can be 6 decimal digits, 8 decimal digits, 10 decimal digits and more. The main concern arises when we need to show such values on front end platforms to the end customers. They might not be interested in so much digits after decimal. So today we will learn various ways in which we can convert / round such number to two decimal places. Things that also matter here is how are you receiving it at your end. If you are receiving it as string you can do it as follows. string decimalNumber = "15.45000000"; string newDecimal= Math.Round(Convert.ToDecimal(decimalNumber, 2).ToString(CultureInfo.InvariantCulture); // Output of newDecimal 15.45 So in the process ab...
Comments
Post a Comment