0

I want to limit decimal place till 4 for below code, how to do that,

var a = Convert.ToDecimal( 80794992640) / (1024 * 1024);
user584018
  • 10,186
  • 15
  • 74
  • 160

2 Answers2

2

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

Mong Zhu
  • 23,309
  • 10
  • 44
  • 76
0

This will round it to 4 decimal places:

var a = Math.Round(Convert.ToDecimal( 80794992640) / (1024 * 1024), 4);
Arion
  • 31,011
  • 10
  • 70
  • 88