I need to get the absolute value of an NSDecimalNumber without loss of precision. I can\'t seem to find a way to do this without converting to decimal or float (with a loss
If you do not want to multiply it, zero subtracting the value will do the trick.
- (NSDecimalNumber *)abs:(NSDecimalNumber *)num {
if ([num compare:[NSDecimalNumber zero]] == NSOrderedAscending) {
// negative value
return [[NSDecimalNumber zero] decimalNumberBySubtracting:num];
} else {
return num;
}
}