Swift Program to Read a Float Number From the User

You are currently viewing Swift Program to Read a Float Number From the User

Swift program to read a float number from the user

// Swift program to read a float number
// from the user

import Swift;

print("Enter Number:")
if let val = readLine(){
    if let num = Float(val)
    {
        print("Entered number is: ",num);
    }
}

Output

Enter Number:
3.14
Entered number is:  3.14

...Program finished with exit code 0
Press ENTER to exit console.

Ranjith

Hi, I'm Manoj a full-time Blogger, YouTuber, Affiliate Marketer, & founder of Coding Diksha. Here, I post about programming to help developers.

Leave a Reply