Question: How do you format a String or Number to two decimal places in Asp.Net Core 3.1 View C# 8? Am getting "No Overload for method 'ToString' takes 1 argument.
Login to See the Rest of the Answer
Answer: You can format numbers to Two Decimal places by using Sting.Format like below:
//If you want to format a string/number in a View (Presentation layer)
@ViewBag.YourVariable.ToString("0.00.##")
Or Simply
@string.Format("{00:C0}", YourVariable.ToString())
//Other way to achieve the same results
Convert.ToDecimal(TheIntegerValueYouWantToShowAsDecimal).Value.ToString("00.00.##");
Azfar Hafiz said:
Thank you for the help!