The `sign` property returns the sign of the double's numerical value: -1.0 for negative values, 1.0 for positive values, and 0.0 for zero.
The syntax of double.sign property is:
double sign
This sign property of double returns the sign of the double's numerical value.
double.sign returns value of type double
.
In this example,
num
with a value of -3.14
.sign
property to obtain the sign of num
.void main() {
double num = -3.14;
double signValue = num.sign;
print('Sign of -3.14: $signValue');
}
Sign of -3.14: -1
In this example,
num
with a value of 42.0
.sign
property to obtain the sign of num
.void main() {
double num = 42.0;
double signValue = num.sign;
print('Sign of 42.0: $signValue');
}
Sign of 42.0: 1
In this example,
num
with a value of 0.0
.sign
property to obtain the sign of num
.void main() {
double num = 0.0;
double signValue = num.sign;
print('Sign of 0.0: $signValue');
}
Sign of 0.0: 0
In this Dart tutorial, we learned about sign property of double: the syntax and few working examples with output and detailed explanation for each example.