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
0
votes
1 answer

Pass a variable to decimalNumberHandlerWithRoundingMode?

Forgive me if I use the wrong terminology as I'm still a little new at iOS development. I've built a calculator-type app and I want users to be able to control how numbers are rounded. Here's the code I'm…
Paul B.
  • 458
  • 3
  • 6
0
votes
1 answer

Adding NSDecimalNumber returning nil

I have this code int countCosts = [Costs count]; countCosts = countCosts - 1; NSDecimalNumber* Total = [[NSDecimalNumber alloc] initWithString:[NSString stringWithFormat:@"%f", 0.0]]; NSDecimalNumber *cost = 0; while (countCosts != -1) { …
0
votes
1 answer

iOS: NSDecimalNumber calculations and accuracy with currencies

I'm calculating back and forth some values and that's where I get the problem. Let's say you have a yearly amount of 100 Dollar and save them as as monthly value to CoreData using decimalnumbers: [self.sumPerMonth decimalNumberByAdding:[amount…
MichiZH
  • 5,587
  • 12
  • 41
  • 81
0
votes
2 answers

NSNumberFormatter rounding incorrectly when converting NSDecimalNumber to NSString

I am running the following code when attempting to calculate the amount of tax applied to a product and display it in a label. This tax should use bankers rounding (same as NSNumberFormatterRoundHalfEven) NSNumberFormatter *formatter =…
0
votes
1 answer

Work with numbers larger than long double

I'm trying to implement a calculator function in my app, and the values will usually be very large along with decimal precision up to 12 digits. I understand the NSDecimalNumber has the decimalNumberWithMantissa function which could be useful…
Milo
  • 5,041
  • 7
  • 33
  • 59
0
votes
2 answers

Not seeing the decimal from a string when converted into NSDecimalNumer

I can't see to find the answer to this, but I have a string that has a decimal point in it, and when I try to convert it to a NSDecimalNumber I only get back the whole number, not the decimal or what would come after it. This is what I am trying:…
icekomo
  • 9,328
  • 7
  • 31
  • 59
0
votes
2 answers

Xcode Decimal x.x.x

xcode can use Decimal 3 place? Example: NSDecimal *test = 1.0.0; //not work double test = 1.0.0; //not work float test = 1.0.0; //not work Can I use decimal 3 place in xcode?
0
votes
1 answer

Problems with NSDecimalNumber Arithmetic when NSDecimalNumbers are stored in NSDictionary from NSExpression Core Data Fetch

I have been experimenting trying to learn how to use NSExpressions to fetch aggregate info from Core Data. I have the fetch working properly but I'm having trouble trying to parse the resulting data for processing. I'm sure I must be missing…
0
votes
1 answer

Multiply or divide numbers larger than 38 digits in objective c

I am writing an app that , among other things will be able to multiply or divide very large numbers by number 19 - Those large numbers could possibly span hundreds of digits . Do you know of a library I could use for that? Thanks in advance. I…
real 19
  • 748
  • 8
  • 32
0
votes
2 answers

Converting an object of an array

I have the following block of codes in my program. for(int k=0;k
Karan Alangat
  • 2,154
  • 4
  • 25
  • 56
0
votes
1 answer

How to get NSDecimalNumber from floatValue having same number of precision that the float value has?

I logged two NSDecimalNumber NSLog(@"%@",[[NSDecimalNumber alloc] initWithFloat:2.675f]); NSLog(@"%@",[[NSDecimalNumber alloc] initWithFloat:2.000f]); I got the results in the console as 10:26 2013-05-16 10:23:20.807 SampleTest[1097:19d03]…
Aswathy Bose
  • 4,279
  • 4
  • 32
  • 44
0
votes
1 answer

NSDecimalNumber addition losing decimal places

I am trying to make a calculator iphone app and my teacher said we had to use NSDecimalNumber. I am having a lot of trouble with it. I am trying to get the addition part of it right, but I am having trouble when adding a number like 1.24 to a whole…
0
votes
1 answer

ios: NSLog show decimal value

NSNumber *weekNum = [dictionary valueForKey:@"inSeasonFor"]; NSDecimalNumber *newWeekNum = ([weekNum intValue] *2)/4; NSLog(@"%", [newWeekNum decimalValue]); How can I divide weekNum*2 by 4 and keep the decimal value and print it?
wwjdm
  • 2,568
  • 7
  • 32
  • 61
0
votes
3 answers

iOS: NSDecimalNumber: not getting expected results

Say I have the following values for these ivars: NSString* percentage = 35 NSString* value = 146 In my code below I am expecting to get 51.1 when I do my multiplication (146*.35) but instead am getting 100. - (NSDecimalNumber*)…
PruitIgoe
  • 6,166
  • 16
  • 70
  • 137
0
votes
1 answer

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…
Jim
  • 890
  • 2
  • 10
  • 22