Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

swift
double
zero
communitycreator

What is the Double.isZero property in Swift?

Theodore Kelechukwu Onyejiaku

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Overview

We use the Double.isZero property in Swift to check if a value is equal to zero.

Syntax

Double.isZero

Return value

A boolean value is returned. If the instance value is equal to zero, the value returned is true. Otherwise, false is returned.

Code example

// create some double values
let d1 = 1.1
let d2 = 0.0
let d3 = -0.5
let d4 = Double.nan
let d5 = Double.infinity
// check if equl to zero
print(d1.isZero) // false
print(d2.isZero) // false
print(d3.isZero) // true
print(d4.isZero) // false
print(d5.isZero) // false
Check if some double values are equal to zero

Explanation

  • Lines 2-6: We create some decimal values.
  • Lines 9-13: Using the isZero property of the Double instance, we check if each of the double values we created is equal to zero. We then print the results.

RELATED TAGS

swift
double
zero
communitycreator

CONTRIBUTOR

Theodore Kelechukwu Onyejiaku

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring