nsdecimalnumber

Trouble with NSDecimalNumber's decimalNumberByDividingBy:withBehavior:

I always seem to run into trouble with NSDecimalNumber! Today, I get this error: "Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSCFNumber decimalNumberByDividingBy:withBehavior:]: unrecognized selector sent to instance 0xd1fb10'" Here is the source of the error: - (void)setUpInstance { ...

Formatted absolute value of an NSNumber

Well, it's actually the sum of an array of NSDecimalNumbers I'd like to get the absolute value of... I constantly feel like I'm fighting the framework with all the conversions & typecasting that are required...from double to NSNumber to NSDecimalNumber and back and...all while trying to maintain the precision that NSDecimalNumber affords...

How do you pass a float to ProgressView from another class?

I'm trying to pass ProgressView a float from a calculation made in another class. I've tried passing it by converting it to a NSDecimalNumber but I can't get it back to a float again when it reaches the destination. There's got to be a better way than this. ...

Calculating sum for decimal values via Core Data not working properly?

Hi everyone, first time I post to this round, so please bear with me if I don't follow all the rules properly. I am writing an app for the iPhone (OS 3.1) and am trying to write some code which lets me add decimals. I have a Core Data entity called SimpleItem with a amount attribute. Here is the test case I wrote: // Create and config...

NSDecimalNumber zeros following decimal point (iPhone SDK)

Hi, I have the following code (...) numberStyle = [NSDecimalNumberHandler decimalNumberHandlerWithRoundingMode:NSRoundPlain scale:2 raiseOnExactness:NO raiseOnOverflow:NO raiseOnUnderflow:NO raiseOnDivideByZero:NO]; strThree = textFi...

NSNumberFormatter and rounding percentage value

here is my code snip, i dont know how to round double numbers. double m = [tmpProduct.msrp doubleValue] ; double d = [tmpProduct.discountPrice doubleValue]; double p = (d * 100 ) / m; here tmpProduct.msrp and mpProduct.discountPrice are (NSDecimalNUmber *) from the operation above I got p = 44.995757 i want to convert it to (45%) ,...

iPhone Currency input using NSDecimal instead of float

Hello, iPhone/Objective-C/Cocoa newbie here. Based on a number of posts on stackoverflow, I have cobbled together an IBAction that I'm using in a basic iPhone calculator app that I'm building. The IBAction works with the numeric keypad to allow entry of decimal numbers without having to enter a decimal point. I am trying very hard to ...

Creating autorelease objects in iPhone Development

I have a requirement to create some NSDecimalNumber objects objects as part of my application (as I require the precision of calculation they offer) but I note that in calculations they return NSDecimalNumber objects which are, presumably, autoreleased. My question is really whether this is potentially problematic in an iPhone applicat...

Cocoa: NSDecimalNumber with mantissa and exponent of 0

Mathematically any number with an exponent of 0 is supposed to equal 1 (my remedial math research assures me). But this code produces 5: [NSDecimalNumber decimalNumberWithMantissa:5 exponent:0 isNegative:NO] Is this something standard in computer programming -- that can be relied upon not being "corrected" in future Cocoa versions? ...

I'm having a problem with decimalNumberBySubtracting and decimalNumberByDividingBy.

Simply put, decimalNumberBySubtracting and decimalNumberByDividingBy are not working ... at all. No errors, just messed up results. I really need to fix this but Im not getting any errors and I cant think of any other way for how to do the calculation!! Im getting numbers like: 25784969139295000000000000000000000000000000000000000...

How to display currency without rounding as string in Xcode?

Hello everyone, I have trouble when I have currency value 999999999999999999.99 From that value, I want to display it as String. The problem is that value always rounded to 1000000000000000000.00 I'm not expect that value rounded. I want the original value displayed. Do you have any idea how to solve this problem? I tried this code f...

Objective-C - How To Remove Characters From a String?

I have a UILable that has a formatted String (formatted for currency), so there is a dollar sign, $21.34. In the core data entity the attribute is of a type double, I am using an NSDecimalNumber to save to the database. self.purchase.name = self.nameTextField.text; NSString *string = self.amountLabel.text NSDecimalNumber *...

Can I use an NSDecimalNumber anywhere that an NSNumber is expected?

NSDecimalNumber is a subclass of NSNumber, and from what I can tell, it implements all of the NSNumber methods as expected for an NSNumber instance. Given that, is it ok to give NSDecimalNumbers to any code that is expecting an NSNumber? The only possible issue might be code that checks that an argument is an instance of NSNumber, but ...

How do I add NSDecimalNumbers?

OK this may be the dumb question of the day, but supposing I have a class with : NSDecimalNumber *numOne = [NSDecimalNumber numberWithFloat:1.0]; NSDecimalNumber *numTwo = [NSDecimalNumber numberWithFloat:2.0]; NSDecimalNumber *numThree = [NSDecimalNumber numberWithFloat:3.0]; Why can't I have a function that adds those numbers: ...

NSDecimalNumber multiplication strangeness

ExclusivePrice, quantity are both NSDecimalNumbers. NSDecimalNumber *price = [exclusivePrice decimalNumberByMultiplyingBy:quantity]; NSLog(@"%@ * %@ = %@", exclusivePrice, quantity, price); The result I get: 2010-04-05 00:22:29.111 TestApp[13269:207] 65 * 2 = -0.00000000000000000000000000000000000000000000000000000000000000000000000...

NSDecimalNumber subtraction

Hello, I need to subtract 0.5 from number a and set the answer to number b. My code looks like it would work but I'm not sure what I'm doing wrong. The error I get Is on the subtraction line, the error says incompatible type for argument 1 of 'decimalNumberBySubtracting:'. Heres my header: (Note: I only showed the numbers because the h...

ceilf and floorf equivalent methods for NSDecimalNumber

Are there equivalent methods for ceilf and floorf for the NSDecimalNumber type? I couldn't seem to find any. ...

Using core plot for iPhone, drawing date on x axis

I have available an array of dictionary that contains NSDate and NSNumber values. I wanted to plot date on X axis. for plotting I need to supply xRanges to plot with some decimal values.I don't understand how can i supply NSdate values to xRange (low and length). And what should be there in this method: -(NSNumber *)numberForPlot:(CPP...

Raise an NSDecimalNumber to a negative power

I need an equivalent to C's pow() function that will work with NSDecimalNumbers. With pow you can use negative numbers e.g. pow(1514,-1234), with NSDecimal's decimalNumberByRaisingToPower: method, you are forced to use an NSUInteger which seems to require a positive value. I'd like to be able to do something like this: [decimalNumber d...

NSDecimalNumber round long numbers

I'm trying to get NSDecimalNumber to print out large numbers, 15 or more digits. At 15 digits I see 111,111,111,111,111. Above 15 digits I see 1,111,111,111,111,110 even though the number being formatted is 1111111111111111. An example to illustrate my problem: NSNumberFormatter *formatter = [[NSNumberFormatter alloc] init]; [formatt...