I want to limit decimal place till 4 for below code, how to do that,
var a = Convert.ToDecimal( 80794992640) / (1024 * 1024);
I want to limit decimal place till 4 for below code, how to do that,
var a = Convert.ToDecimal( 80794992640) / (1024 * 1024);
I guess you can round it if you want to fix it to 4 digits:
var a = Math.Round(Convert.ToDecimal( 80794992640) / (1024 * 1024),4 );
but if your concern is to restrict it in the display then you can just apply the restriction in the ToString
method:
a.ToString("0.####");
the latter method will keep the precision for the calculations but cut the precision only for display
This will round it to 4 decimal places:
var a = Math.Round(Convert.ToDecimal( 80794992640) / (1024 * 1024), 4);