Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

dart
int

Integer in Dart

Educative Answers Team

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);
}

RELATED TAGS

dart
int
Copyright ©2022 Educative, Inc. All rights reserved
RELATED COURSES

View all Courses

Keep Exploring