I have a decimal number :
decimal a = 0.8537056986486486486486486486;
I want to show it as string with only 8 digit after point : a equals -> "0.85370569". How can I do it ?
I have a decimal number :
decimal a = 0.8537056986486486486486486486;
I want to show it as string with only 8 digit after point : a equals -> "0.85370569". How can I do it ?
Try using
a.ToString("D8");
This should convert it to the correct format.
Edit:
As said in the comments, D is only used for integral types, thus not for decimals and such. Use
static void Main(string[] args)
{
decimal d = (decimal)0.8537056986486486486486486486;
Console.WriteLine(d.ToString("N8"));
Console.ReadLine();
}
instead.
This will format it to 0.85370570
To perform this numerically you could use:
decimal a = (decimal) 0.8537056986486486486486486486;
String test = (Math.Truncate(100000000 * a) / 100000000).ToString();