0
0
Swiftprogramming~15 mins

Int, Double, Float number types in Swift - Mini Project: Build & Apply

Choose your learning style9 modes available
Working with Int, Double, and Float Number Types in Swift
📖 Scenario: You are creating a simple Swift program to understand how to use different number types: Int, Double, and Float. These types help you store whole numbers and decimal numbers with different precision.
🎯 Goal: Build a Swift program that declares variables of type Int, Double, and Float, assigns values to them, and prints their values to see how they work.
📋 What You'll Learn
Declare an Int variable named wholeNumber with the value 42.
Declare a Double variable named decimalNumber with the value 3.14159.
Declare a Float variable named smallDecimal with the value 2.718.
Print all three variables with descriptive text.
💡 Why This Matters
🌍 Real World
Understanding number types is essential for any app that works with calculations, measurements, or data input.
💼 Career
Many programming jobs require knowledge of how to handle different numeric data types correctly to avoid errors and ensure precision.
Progress0 / 4 steps
1
Declare an Int variable
Create a variable called wholeNumber of type Int and set it to 42.
Swift
Need a hint?

Use var to declare a variable and specify the type Int with a colon.

2
Declare Double and Float variables
Add a variable called decimalNumber of type Double with the value 3.14159, and a variable called smallDecimal of type Float with the value 2.718.
Swift
Need a hint?

Remember to specify the type after the variable name with a colon, and assign the correct decimal values.

3
Print the variables
Use three print statements to display the values of wholeNumber, decimalNumber, and smallDecimal with descriptive text. For example, print "Whole number: 42" for wholeNumber.
Swift
Need a hint?

Use string interpolation with \(variableName) inside the print statements.

4
Run and see the output
Run the program to display the values of wholeNumber, decimalNumber, and smallDecimal.
Swift
Need a hint?

Check the console output matches the expected text exactly.