My iPhone has a line of code that looks like this:
double decimal2 = abs(newLocation.coordinate.longitude - degrees);
I’m trying to ensure that the value of decimal2 is always positive. However, decimal2 is currently -82.
Can anyone explain this? I’m not doing anything else to the value of decimal2.
Thanks.
would suggest you to use NSDecimalNumber
You could use the built-in functions of the
NSDecimalNumberclass to compare the number to zero, then multiply by -1 as appropriate. For example:in this case , there’s no loss of precision