3

I'm working on an iOS Objective C app where you accumulate a large amount of wealth. By the end of the app, the amount of money users can accumulate is more than a long long can handle. What data type should I use instead? I know I could use an unsigned long, but that only adds a little bit more. I need users to have like 6 more digits to be safe, so instead of the max being 18,446,744,073,709,551,615 (about 1.8x10^19), it would be ideal to have something like 1.8x10^25 as my maximum value.

Precision isn't actually all that important in the end, but it would defiantly save me time to not have to do more than just changing data types throughout my application. Any ideas?

rmaddy
  • 314,917
  • 42
  • 532
  • 579
Kjell Connelly
  • 247
  • 3
  • 9

1 Answers1

1

Short Answer
Go for a 3rd party library.

Long Answer
When dealing with large numbers, probably one of the most fundamental design decisions is how am I going to represent the large number?

Will it be a string, an array, a list, or custom (homegrown) storage class.

After that decision is made, the actual math operations can be broken down in smaller parts and then executed with native language types such as int or integer.

Even with strings there is a limit in the number of characters or "numbers" in the number, as indicated here:

What is the maximum possible length of a .NET string?

You might also want to check: Arbitrary description Arithmetic

Community
  • 1
  • 1
Joe
  • 2,386
  • 1
  • 22
  • 33
  • Why a 3rd party library? Just use `NSDecimalNumber` which supports much bigger numbers than the OP needs. – rmaddy Aug 13 '15 at 18:36