0

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

var a = Convert.ToDecimal( 80794992640) / (1024 * 1024);
user584018
  • 8,077
  • 12
  • 50
  • 108

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
  • 21,868
  • 8
  • 38
  • 71
0

This will round it to 4 decimal places:

var a = Math.Round(Convert.ToDecimal( 80794992640) / (1024 * 1024), 4);
Arion
  • 30,443
  • 10
  • 68
  • 86