Questions tagged [nsdecimalnumber]

NSDecimalNumber, an immutable subclass of NSNumber, provides an object-oriented wrapper for doing base-10 arithmetic. An instance can represent any number that can be expressed as mantissa x 10^exponent where mantissa is a decimal integer up to 38 digits long, and exponent is an integer from –128 through 127.

NSDecimalNumber, an immutable subclass of NSNumber (), provides an object-oriented wrapper for doing base-10 arithmetic. An instance can represent any number that can be expressed as mantissa x 10^exponent where mantissa is a decimal integer up to 38 digits long, and exponent is an integer from –128 through 127.

244 questions
3
votes
2 answers

Why subtracting NSDecimalNumbers do not work - Swift 3

Why am I getting 0 when subtracting 5.0 from 650.50 using the subtracting() method? in the following code, adding, multiplying and dividing work fine, but why subtracting doesn't? What am I doing wrong? See code in IBM's…
fs_tigre
  • 10,650
  • 13
  • 73
  • 146
3
votes
3 answers

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…
james_womack
  • 10,028
  • 6
  • 55
  • 74
3
votes
1 answer

AlamoFire responseJSON decimal precision

I'm using AlamoFire to call my web service: ApiManager.manager.request(.GET, webServiceCallUrl, parameters: ["id": 123]) .validate() .responseJSON { response in switch response.result { case .Success: …
Joseph
  • 2,706
  • 6
  • 42
  • 80
3
votes
2 answers

How to Find the Sum of Array Type NSDecimalNumber

I'm building a budget app in Swift. The NSDecimalNumber is first added to an array after an action (below). Then the NSDecimalNumber is converted to CurrencyFormat for TableView, and appended to a separate string array. How can I find the sum of…
user4732515
3
votes
2 answers

Converting double to NSDecimalNumber while maintaining accuracy

I need to convert the results of calculations performed in a double, but I cannot use decimalNumberByMultiplyingBy or any other NSDecimalNumber function. I've tried to get an accurate result in the following ways: double calc1 = 23.5 * 45.6 * 52.7; …
Croises
  • 18,570
  • 4
  • 30
  • 47
3
votes
2 answers

Very big ID in JSON, how to obtain it without losing precision

I have IDs in JSON file and some of them are really big but they fit inside bounds of unsigned long long int. "id":9223372036854775807, How to get this large number from JSON using objectForKey:idKey of NSDictionary? Can I use NSDecimalNumber?…
Prettygeek
  • 2,461
  • 3
  • 22
  • 44
3
votes
2 answers

NSDecimal equal to NSDecimalNumber value?

I am looking for an effective way to save NSDecimalNumber with other data in NSData buffer. I have not found a method to do it directly from NSDecimalNumber. However, it is easy to convert it with : NSDecimal value = [theDecimalNumber…
Croises
  • 18,570
  • 4
  • 30
  • 47
3
votes
1 answer

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…
Nick Forge
  • 21,344
  • 7
  • 55
  • 78
3
votes
7 answers

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

I have a UILabel 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 =…
iAm
  • 219
  • 3
  • 5
  • 12
3
votes
3 answers

Loosing fractional zeros when formatting a NSDecimalNumber with NSNumberFormatter

I use the following code to format string numbers by adding thousand separation points: NSDecimalNumber *decimalNumber = [NSDecimalNumber decimalNumberWithString:@"0.000"]; NSLog(@"decimalNumber = %@",decimalNumber); NSNumberFormatter…
iOS Dev
  • 4,143
  • 5
  • 30
  • 58
3
votes
1 answer

Rounding issus insert NSDecimalNumber into Sqlite

the NSDeciamlNumber 3.33 becomes 0.32999999999999996 when it insert into database The the sql is correct, but the data become 0.32999999999999996 when sql execute. I'm using FMDB, I tried column type REAL, DECIMAL, they have same issue. If there a…
allenwei
  • 4,047
  • 5
  • 23
  • 26
3
votes
1 answer

NSDecimalNumber with fraction returning large number when raised to high power?

Ok so Im trying to raise this fractional amount to a high power. But for some reason, according to the logs I just get a very high number and sometimes even a NSDecimalOverflor error. Could someone please help me with this? NSDecimalNumber *number…
Michael Giba
  • 118
  • 4
3
votes
2 answers

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…
Nnp
  • 1,813
  • 7
  • 36
  • 62
3
votes
3 answers

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

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…
3
votes
2 answers

NSDecimalNumber sum

In my ios project I use two entities (CoreData): Person and Gifts with To-Many Relationship I know how to calculate the sum of gifts to one person: NSDecimalNumber *orderSum=[person.gifts valueForKeyPath:@"@sum.priceOfGift"]; But how do I calculate…
German
  • 137
  • 17