Created
December 28, 2011 17:37
-
-
Save MrRooni/1528822 to your computer and use it in GitHub Desktop.
Revisions
-
Michael Fey created this gist
Dec 28, 2011 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,25 @@ // Call this method with [NSDecimalNumber zero] to get negative zero, or NaN. - (NSDecimalNumber *)negativeAmount:(NSDecimalNumber *)anAmount { if (anAmount == nil) { return [NSDecimalNumber zero]; } NSDecimal decimalAmount = [anAmount decimalValue]; decimalAmount._isNegative = 1; return [NSDecimalNumber decimalNumberWithDecimal:decimalAmount]; } // Here's a version that handles that situation properly: - (NSDecimalNumber *)negativeAmount:(NSDecimalNumber *)anAmount { if (anAmount == nil || [anAmount isZero]) { return [NSDecimalNumber zero]; } NSDecimal decimalAmount = [anAmount decimalValue]; decimalAmount._isNegative = 1; return [NSDecimalNumber decimalNumberWithDecimal:decimalAmount]; }