Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is use of underScore in Double value in swift? [duplicate]

Tags:

ios

swift

I just recently look into Apple documentation I found code like below

extension Double {
    var km: Double { return self * 1_000.0 }
    var m: Double { return self }
    var cm: Double { return self / 100.0 }
    var mm: Double { return self / 1_000.0 }
    var ft: Double { return self / 3.28084 }
}

What is the use of "_" in double value? it's working without error why?

like image 430
Phani Sai Avatar asked Jan 27 '26 10:01

Phani Sai


1 Answers

Just a way to improve readability. According to Swift documentation:

Numeric literals can contain extra formatting to make them easier to read. Both integers and floats can be padded with extra zeros and can contain underscores to help with readability. Neither type of formatting affects the underlying value of the literal.

like image 148
Mo Abdul-Hameed Avatar answered Jan 29 '26 01:01

Mo Abdul-Hameed