Int and double

aninarafath6

Anin Arafath

Posted on February 11, 2022

Int and double

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.
}
Enter fullscreen mode Exit fullscreen mode

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.
}
Enter fullscreen mode Exit fullscreen mode

error when assign value

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.
}
Enter fullscreen mode Exit fullscreen mode

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.
}
Enter fullscreen mode Exit fullscreen mode

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 .

💖 💪 🙅 🚩
aninarafath6
Anin Arafath

Posted on February 11, 2022

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related

Int and double
dart Int and double

February 11, 2022