Hi All
I have the fraction 256139/25631, which I have stored in a Decimal data
types, due to it having the highest precision. When I display this
using Console.Writeline, it only displays a precision of 15 digits
(9.99...). I know that Decimals hold higher precisions than this, but
I don't know how I can get it to display all digits. It seems to
always round the value. I have tried using NumberFormatInfo classes
and all sorts of tricks, but nothing seems to work. Any ideas?
cheers
MQ
Jon Skeet [C# MVP] - 01 Jul 2005 06:58 GMT
> I have the fraction 256139/25631, which I have stored in a Decimal data
> types, due to it having the highest precision.
My guess is that you're doing the division using doubles, and then
converting the result to a decimal - in which case you've lost the
extra precision already.
The following program shows the difference - I suspect you're doing the
second thing, when you should be doing the first:
using System;
public class Test
{
static void Main()
{
Decimal d = 256139m/25631m;
Console.WriteLine (d);
d = (decimal)(256139d/25631);
Console.WriteLine (d);
}
}

Signature
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too