Questions tagged [nsdecimal]
11 questions
4
votes
1 answer
When is it better to use an NSDecimal, NSDecimalNumber instead of a double?
For simple uses, such as tracking weight values like 65.1kg, is there any benefit of going with NSDecimal/NSDecimalNumber over double?
My understanding here is double (or even float) provides more than enough precision in such cases. Please correct…

Gaurav Sharma
- 2,680
- 3
- 26
- 36
4
votes
3 answers
Set NSDecimal to zero
What are the different ways of setting a NSDecimal to zero? I'm not keen on any of the 3 I found so far.
NSDecimal zero = {0}; // Not obvious what's going on here.
NSDecimal zero = @(0).decimalValue; // @(0) appears to always return the same…

hpique
- 119,096
- 131
- 338
- 476
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
1
vote
0 answers
NSDecimalNumber vs NSNumberFormatter numbers from same invariant string produce diff results
Not understanding why using NSNumberFormatter vs NSDecimalNumber methods to convert strings to decimal numbers are producing different results.
NSNumberFormatter *customNumFmt = [[NSNumberFormatter alloc] init];
customNumFmt.locale = [[NSLocale…

stonedauwg
- 1,328
- 1
- 14
- 35
1
vote
2 answers
How can I get NSDecimal to round to the nearest integer value?
I am using NSDecimal because I have to store extremely large values for my application. I would like to be able to use the NSDecimalDivide function to divide two NSDecimals and round the result to the nearest integer.
NSDecimal testOne =…

Richard D
- 142
- 8
1
vote
2 answers
Converting very large NSDecimal to string eg. 400,000,000,000 -> 400 T and so forth
I am making a game that requires me to use very large numbers. I believe I am able to store very large numbers with NSDecimal. However, when displaying the numbers to users I would like to be able to convert the large number to a succinct string…

Richard D
- 142
- 8
1
vote
0 answers
What's the best way to convert an inputed numeric string to a NSDecimalNumber, considering the number of fraction digits for a given locale?
Is there an API for this? Or maybe a better way of doing it?
Here's what I'm trying to acomplish:
In is a numeric string. Out, is a NSDecimalNumber
// this one is for US:
in: 1 out: 0.01
in: 12 out: 0.12
in: 123 out: 1.12
// a diferent locale…

nmdias
- 3,888
- 5
- 36
- 59
0
votes
1 answer
Why does Decimal not support high Doubles?
let highDouble = 1.7976931348623e+308 // Just under Double.greatestFiniteMagnitude
print(highDouble) // 1.7976931348623e+308
let highDecimal = Decimal(highDouble)
print(highDecimal) // 17976931348623005696000000000000000000000000000000000
This is…

Ky -
- 30,724
- 51
- 192
- 308
0
votes
1 answer
Xcode decimal keyboad produces different result on simulator vs device
I use NSDecimalNumber in my app to do alot of calculations entered in textboxes. I tested it on the simulator and device ( not sure if it changed in iOS 8 or if i just didn't notice ) but on storyboard I use the decimal keyboard.
When i run the app…

ildsarria
- 281
- 3
- 10
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?

Masataga.Takashi
- 87
- 8
-2
votes
1 answer
How to perform NSDecimal Math?
I am attempting to perform basic NSDecimal math such as addition multiplication and subtraction of NSDecimals. Is this possible to accomplish?
trying to use NSDecimalAdd
getting error
NSDecimal' to parameter of incompatible type 'NSDecimal *…

Richard D
- 142
- 8