Convert double (0.1) to BigRational and back

456 views Asked by At

I must be missing something, but when I try to create a BigRational from double value 0.1 it gives me a really long nonsense value. Converting it back gives 0.0:

double d = 0.1;                      // 0.1
BigRational br = new BigRational(d); // 3602879701896397/71213961919824440...
double d2 = (double)br;              // 0.0

What am I missing? I know 0.1 is not representable exactly in a System.Double but surely BigRational can approximate it well enough to round-trip it?

1

There are 1 answers

0
kcnygaard On

As @elgonzo explains:

This was already a known issue about a year ago: bcl.codeplex.com/workitem/13051.

A commenter on the referenced work item uploaded a fix that reads in 0.1 correctly.