Can someone help me, I need 4 decimal places to appear if it has a data type double
:
Console.WriteLine(num);
For example 0.2544 is displayed.
Can someone help me, I need 4 decimal places to appear if it has a data type double
:
Console.WriteLine(num);
For example 0.2544 is displayed.
The easiest way:
In this case the format string
N4
means number format with 4 decimal places.Please note the following:
More about numeric format strings: Standard numeric format strings
I guess your problem is that the Math.Round option rounds the values and you don't want that, if that's the case you can get the decimals "truncated" like this:
As you'll notice, the number of zeros in the auxiliary value '10000' is the number of decimal places you want.
You can create an extensionMethod to make this easier:
And so call Truncate directly
If it's just for display purposes, you can use :
Maybe "Convert.ToInt32(value)" will work for you.
N
refers toNumber
, which would indicate how many decimal digits you want to put.