| Start |
|---|
| Convert numbers to/from strings Use String initializers for converting numbers into strings: Or use string interpolation (opens new window) for simple cases: Use initializers of numeric types to convert strings into numbers: |
| Number types and literals Swift's built-in numeric types are:
LiteralsA numeric literal's type is inferred from context: Underscores ( Floating point literals may be specified using significand (opens new window) and exponent parts ( Integer literal syntaxFloating-point literal syntax |
Rounding roundRounds the value to the nearest whole number with x.5 rounding up (but note that -x.5 rounds down). ceilRounds any number with a decimal value up to the next larger whole number. floorRounds any number with a decimal value down to the next smaller whole number. IntConverts a Notes
|
Convert one numeric type to another Integer initializers produce a runtime error if the value overflows or underflows: Float-to-integer conversion rounds values towards zero: Integer-to-float conversion may be lossy: |
| Random number generation
This gives you random integers in the range The maximum value for Examples: General form: where Notes
|
| Exponentiation In Swift, we can exponentiate In the code below, the base (5) is set to the power of the exponent (2) : |
Read Article
https://develop.horje.com/learn/1434/reference