The dart programming language is similar to c ,cpp and javascript there is some difference in syntax that's it.
Data Type in Dart
- int & double
1. Int
- Int is a numeric data type in dart.
- Int data type is mainly used for store integer numbers.
- In this data type can't hold floating numbers.
for example :-
void main(){
// declare an integer variable.
int number = 10;
print(number); // result -> 10.
}
the output will be 10.
the next code block is incorrect way, we can't assign the floating value to integer datatype.
void main(){
// declare an integer variable.
// and trying to assign a floating value.
int number = 10.5;
print(number); // result -> error occurs.
}
in this case we will get an error due to we are trying to assign a floating value to integer data variable.
so how we can create a floating variable ? Let's make it.
2.double
Double is also numeric type in dart.
This data type can hold floating values.
also we can save integer data type but it's really happening storing value as a floating .
for example :-
void main(){
// declare a floating variable.
double number = 10.4;
print(number); // result -> 10.4.
}
the result will be 10.4 .
also we can store values like integer for example :-
void main(){
// declare a floating variable.
double number = 4;
print(number); // result -> 4.0.
}
in this case we declared variable as floating variable by using double datatype.
Are you thinking how it can possible?
don't worry about it it just storing 4.0, it's really storing as a floating value.
so the result will be 4.0 .
Top comments (0)