Forum Xamarin.Forms
We are excited to announce that the Xamarin Forums are moving to the new Microsoft Q&A experience. Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

We encourage you to head over to Microsoft Q&A for .NET for posting new questions and get involved today.

Xamarin.Essentials unit converters should be using decimals and not doubles

ashlarashlar USMember ✭✭

Doubles have imprecisions which can cause odd things to happen in your app. For instance this code:

        double a1 = 1;

        double c1 = UnitConverters.CelsiusToFahrenheit(a1);
        double c2 = UnitConverters.FahrenheitToCelsius(c1);

        if(c2 == a1)
        {
            // will never get here
        }

// c2 equals something like .999999998 and a1 equals 1

These methods should be overloaded to be able to take decimals and return decimals.

Sign In or Register to comment.