
- Swift Tutorial
- Swift - Home
- Swift - Overview
- Swift - Environment
- Swift - Basic Syntax
- Swift - Data Types
- Swift - Variables
- Swift - Optionals
- Swift - Tuples
- Swift - Constants
- Swift - Literals
- Swift - Operators
- Swift - Decision Making
- Swift - Loops
- Swift - Strings
- Swift - Characters
- Swift - Arrays
- Swift - Sets
- Swift - Dictionaries
- Swift - Functions
- Swift - Closures
- Swift - Enumerations
- Swift - Structures
- Swift - Classes
- Swift - Properties
- Swift - Methods
- Swift - Subscripts
- Swift - Inheritance
- Swift - Initialization
- Swift - Deinitialization
- Swift - ARC Overview
- Swift - Optional Chaining
- Swift - Type Casting
- Swift - Extensions
- Swift - Protocols
- Swift - Generics
- Swift - Access Control
- Swift Useful Resources
- Swift - Compile Online
- Swift - Quick Guide
- Swift - Useful Resources
- Swift - Discussion
Swift program to convert double type variables to int
This tutorial will discuss how to write swift program to convert double type variable to int.
Swift support various datatypes and double and integers are one of them. Double is used to represent 64-bit floating point numbers. For example, 34.55656, 9.8283, etc. To create a double type variable we use Double keyword. Whereas Integer represent numeric values like 2, 3, 45, 6, etc. And to create integer type variable we use Int keyword.
To convert double type variable into int we uses Int() function. This function convert any data type into integer.
Syntax
Following is the syntax −
Int(variableName)
Below is a demonstration of the same −
Input
Suppose our given input is −
Num = 52.324
Output
The desired output would be −
Integer = 52
Example
The following program shows how to convert double type variable to int.
import Foundation import Glibc // Double type variable var mynum : Double = 73.93 // Convert double into integer // Using Int() function var myVar = Int(mynum) print("Integer:", myVar) print("Type of myVar variable:", type(of: myVar))
Output
Integer: 73 Type of myVar variable: Int
- Related Articles
- Golang Program to convert double type variables to int
- Haskell Program to convert int type variables to double
- Haskell Program to convert double type variables to int
- Swift Program to convert int type variable to double
- C++ Program to convert double type Variables into int
- Swift Program to Convert Char type variables to Int
- C++ Program to convert int Variables into double
- Haskell Program to convert int type variables to char
- Haskell Program to convert int type variables to long
- Golang Program to convert long type variables to int
- Golang Program to convert int type variables to long
- C++ Program to Convert long Type Variables to int
- C++ Program to Convert int Type Variables to long
- Golang Program to convert int type variables to String
- Haskell Program to convert int type variables to String
