Reference Materials
Certification Courses
Created with over a decade of experience and thousands of feedback.
Python online compiler
JavaScript online compiler
SQL online compiler
Java online compiler
HTML online compiler
C online compiler
C++ online compiler
C# online compiler
PHP online compiler
Swift online compiler
Kotlin online compiler
TypeScript online compiler
Go online compiler
Rust online compiler
Scala online compiler
Dart online compiler
R online compiler
Ruby online compiler
Swift Double abs()
In this tutorial, we will learn about the Swift Double abs() method with the help of examples.
The abs() method returns the absolute value of the given value.
Example
var value = -20
// find absolute value of -20
var absoluteNumber = abs(value)
print(absoluteNumber)
// Output: 20
abs() Syntax
The syntax of the abs() method is:
abs(num)
abs() Parameters
The abs() method takes one parameter
- num - a signed number
abs() Return Values
The abs() method returns the absolute value of num.
Example: Swift Double abs()
var value1 = -20
// find absolute value of -20
var result1 = abs(value1)
print("Absolute value of -20 is:", result1)
var value2 = -33.33
// find absolute value of -33.33
var result2 = abs(value2)
print("Absolute value of -33.33 is:", result2)
Output
Absolute value of -20 is: 20 Absolute value of -20 is: 33.33
Here, we have used the abs() method to find the absolute value of the given numbers: value1 and value2.
Did you find this article helpful?