What is the meaning of underscores in swift numbers

Well it's just for code readability. As per Apple developer doc 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.

let myDouble1 : Double = 123_456.789_123
let MyDouble2 : Double = 123456.789123
if myDouble1 == MyDouble2 {
    print("Yes they are the same!")
}

No comments:

Post a Comment

NO JUNK, Please try to keep this clean and related to the topic at hand.
Comments are for users to ask questions, collaborate or improve on existing.