Decimal
is the numeric type capable of holding the largest value in Swift. However,you can't declare a Decimal
literal, since integer literals are inferred to Int
, while floating point literals are inferred to Double
, so you need to initialise the Decimal
from a String
literal.
let number = Decimal(string: "321321321155564654646546546546554653334334")!
From the documentation of NSDecimalNumber
(whose Swift version is Decimal
and hence their numeric range is equivalent):
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.
If you need to be able to represent arbitrary-length numbers in Swift, you need to use a 3rd party library (or create one yourself), there's no built-in type that could handle this in Swift.