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

NSDecimalNumber setting and getting value

I have the following property: @property (nonatomic, assign) NSDecimalNumber askingPrice; I am trying to set the value from a textfield: myManager.askingPrice = [self.askingPriceTextField.text doubleValue]; I get the following warning: Assigning…
Strong Like Bull
  • 11,155
  • 36
  • 98
  • 169
3
votes
3 answers

Converting from `NSDecimal` or `NSDecimalNumber` to C#'s `decimal` type

I've got an NSDecimalNumber from StoreKit's SKProduct class, and I want to convert it to C#'s decimal type to minimize loss of precision. Is there a straightforward way to do such a thing? I figure my two choices are: Assume that I understand the…
sblom
  • 26,911
  • 4
  • 71
  • 95
3
votes
1 answer

Objective - C, Using NSDecimalNumberHandler and NSDecimalNumberBehaviors protocol

A calculator class seems to be a popular starting point for those learning Objective-C. So in my 'calculator' class, I have defined my addition function to use the 'decimalNumberByAdding:withBehavior:' method. The '_behavior' is defined in the…
H_H
  • 605
  • 1
  • 9
  • 13
2
votes
2 answers

how to calculate loan repayment

Hey I am trying to calculate monthly repayments based on loan amount, interest rate and number of years. I have come up with the following, however there seems to be a difference between my calculations and other loan calculators on the internet. my…
user1214037
  • 153
  • 3
  • 12
2
votes
1 answer

Create a running sum in a UITableView

I have a UITableView populated (previously saved via a button in navbar), with transactions. Each row has five UILabel: date, description, person, value (deposits and withdraws) balance. The table is sort by date. How can I obtain the daily…
Memo
  • 39
  • 7
2
votes
3 answers

Isn't NSDecimalNumber supposed to be able to do base-10 arithmetic?

NSDecimalNumber *minVal = [NSDecimalNumber decimalNumberWithString:@"0.0"]; NSDecimalNumber *maxVal = [NSDecimalNumber decimalNumberWithString:@"111.1"]; NSDecimalNumber *valRange = [maxVal decimalNumberBySubtracting:minVal]; CGFloat floatRange =…
DTs
  • 1,196
  • 1
  • 11
  • 28
2
votes
1 answer

How would I decode a NSDecimalNumber without loss of precision?

is there any way to tell JSONDecoder to convert incoming decimals to Strings? public struct Transaction: Decodable { public let total: NSDecimalNumber? enum CodingKeys: String, CodingKey { case total = "AMOUNT" } public…
Anton Tropashko
  • 5,486
  • 5
  • 41
  • 66
2
votes
1 answer

How to parse Decimal from String without losing precision?

I am dealing with money amounts in my app so precision is obviously very important and Decimal/NSDecimal number is supposed to be the way to handle money in swift. I want to convert between Decimal and String while keeping precision. (parsing API…
pkorosec
  • 676
  • 8
  • 13
2
votes
2 answers

How to convert NSDecimalNumber to byte array if NSDecimalNumber is bigger than Uint64?

I want to convert an NSDecimalNumber to a byte array. Also, I do not want to use any library for that like BigInt, BInt, etc. I tried this one: static func toByteArray(_ value: T) -> [UInt8] { var value = value return…
KingHodor
  • 537
  • 4
  • 17
2
votes
1 answer

getting the sum of all instances of Entity B from a given instance of Entity A

I have a to-many relationship between Entity A and Entity B (iOS Core Data app). I need to get the sum of the NSDecimalNumber attribute of all instances of Entity B from a given instance of Entity A. Does anyone have a tutorial or example of this?
JohnnyRedTruss
  • 259
  • 3
  • 11
2
votes
2 answers

Show NSDecimalNumber as currency in IB

I have a core data entity with a property amount, which is a NSDecimalNumber. For this property the entity's class has a method defined with an NSDecimalNumber as argument. In Interface Builder I bound a table column to this property (using an…
2
votes
1 answer

NSDecimalNumber usage for precision with currency in Swift

I've read a lot that NSDecimalNumber is the best format to use when using currency. However, I'm still getting floating point issues. For example. let a: NSDecimalNumber = 0.07 //0.07000000000000003 let b: NSDecimalNumber = 7.dividing(by: 100)…
LateNate
  • 763
  • 9
  • 22
2
votes
1 answer

NSDecimal vs Float (iOS)

I've come across some blogs and forum posts where people say one should use NSDecimalNumber instead of floats when dealing with currency. I find I have to convert from NSDecimalNumber to Floats/Doubles in order to do some arithmetic which in my…
HM1
  • 1,684
  • 2
  • 18
  • 25
2
votes
2 answers

[NSDecimalNumber retain]: message sent to deallocated instance 0x174222220, but why?

I seem to be getting this error. *** -[NSDecimalNumber retain]: message sent to deallocated instance 0x174222220 The first time I run the app, the code executes fine, but if I got back to that VC, the app crashes with the message above. I did some…
icekomo
  • 9,328
  • 7
  • 31
  • 59
2
votes
2 answers

NSDecimalNumber math operation causes app to crash when UITextField includes currency symbol

I am using the following code to try and do simple math operations based on two text fields. The issue is that the text field has the currency symbol in them and it causes NSDecimalNumber to crash, if I have the text fields without the currency…
Matt Douhan
  • 2,053
  • 1
  • 21
  • 40