Integer in Dart

In the Dart programming language, an integer is represented by the int keyword. As we may know, integers include whole numbers (i.e., non-decimal positive and negative numbers). For every integer, four bytes are allocated in the memory.

svg viewer

Code

import 'dart:convert';
void main() {
// Two integers
int num1 = 6;// positive number
int num2 = -6;// negative number
// printing both numbers
print(num1);
print(num2);
}

The code below throws an error because it is not possible to assign a fractional value to an integer.

For fractional values, we use double datatype.

import 'dart:convert';
void main() {
// Two integers
int num = 6.56;// fractional value
// printing both numbers
print(num);
}
New on Educative
Learn any Language for FREE all September 🎉
For the entire month of September, get unlimited access to our entire catalog of beginner coding resources.
🎁 G i v e a w a y
30 Days of Code
Complete Educative’s daily coding challenge every day in September, and win exciting Prizes.

Free Resources

Copyright ©2025 Educative, Inc. All rights reserved