Basics of Numbers in Dart Last Updated : 25 Mar, 2025 Comments Improve Suggest changes Like Article Like Report Like other languages, Dart Programming also supports numerical values as Number objects. The number in Dart Programming is the data type that is used to hold the numeric value. Dart numbers can be classified as: int (Integer) The int data type is used to represent whole numbers.Declaring Integer in Dartint var_name; Example : Dart // Declaring an integer variable int age = 25; double (Floating-Point Number)The double data type is used to represent 64-bit floating-point numbers.Declaring Double in Dartdouble var_name; Example : Dart // Declaring a double variable double pi = 3.1415; Example Usage : Dart void main() { // declare an integer int num1 = 2; // declare a double value double num2 = 1.5; // print the values print(num1); print(num2); } Output: 21.5Note: The num is actually the superclass of int and double, means int and double extend num.Parsing in DartThe parse() function converts a valid numeric string into a number, but if the string is not numeric, it throws a FormatException.Example : Dart void main() { // Parsing string values into // numeric types using num.parse() // Converts "1" into a numeric value (int) var a1 = num.parse("1"); // Converts "2.34" into a numeric value (double) var b1 = num.parse("2.34"); // Performing addition operation on parsed numbers var c1 = a1 + b1; // Printing the result of the addition print("Sum = ${c1}"); // Output: Sum = 3.34 } Output: Sum = 3.34Properties of Numbers in DartPropertyDescriptionhashcodeThis property is used to get the hash code of the given numberisFiniteIf the given number is finite, then this property will return trueisInfiniteIf the number is infinite, then this property will return trueisNan(Not a Number) returns true if the number is not a valid numeric value, not based on negativity.isNegativeIf the number is negative then this property will return truesignThis property is used to get -1, 0, or 1 depending upon the sign of the given numberisEvenIf the given number is an even then this property will return trueisOddIf the given number is odd then this property will return trueImplementation of Properties: Dart void main() { int num1 = 10; double num2 = -5.5; double num3 = double.infinity; // NaN (Not a Number) double num4 = 0 / 0; // hashCode: Returns the hash // code of the number print("Hash code of num1: \${num1.hashCode}"); print("Hash code of num2: \${num2.hashCode}"); // isFinite: Returns true if // the number is finite print("Is num1 finite? \${num1.isFinite}"); // true print("Is num3 finite? \${num3.isFinite}"); // false (infinity is not finite) // isInfinite: Returns true if // the number is infinite print("Is num3 infinite? \${num3.isInfinite}"); // true print("Is num1 infinite? \${num1.isInfinite}"); // false // isNaN: Returns true if // the number is Not-a-Number (NaN) print("Is num4 NaN? \${num4.isNaN}"); // true print("Is num1 NaN? \${num1.isNaN}"); // false // isNegative: Returns true if // the number is negative print("Is num2 negative? \${num2.isNegative}"); // true print("Is num1 negative? \${num1.isNegative}"); // false // sign: Returns -1 for negative, // 0 for zero, and 1 for positive numbers print("Sign of num1: \${num1.sign}"); // 1 print("Sign of num2: \${num2.sign}"); // -1 print("Sign of 0: \${0.sign}"); // 0 // isEven: Returns true if // the number is even print("Is num1 even? \${num1.isEven}"); // true (10 is even) print("Is num2 even? \${num2.toInt().isEven}"); // false (-5 is odd) // isOdd: Returns true if // the number is odd print("Is num1 odd? \${num1.isOdd}"); // false (10 is even) print("Is num2 odd? \${num2.toInt().isOdd}"); // true (-5 is odd) } Output:Hash code of num1: 10Hash code of num2: 250189098Is num1 finite? trueIs num3 finite? falseIs num3 infinite? trueIs num1 infinite? falseIs num4 NaN? trueIs num1 NaN? falseIs num2 negative? trueIs num1 negative? falseSign of num1: 1Sign of num2: -1Sign of 0: 0Is num1 even? trueIs num2 even? falseIs num1 odd? falseIs num2 odd? trueMethods of Numbers in DartMethodDescriptionabs()This method gives the absolute value of the given numberceil()This method gives the ceiling value of the given numberfloor()This method gives the floor value of the given numbercompareTo()This method compares the value with other numbersremainder()This method gives the truncated remainder after dividing the two numbersround()This method returns the round of the numbertoDouble()This method gives the double equivalent representation of the numbertoInt()This method returns the integer equivalent representation of the numbertoString()This method returns the String equivalent representation of the numbertruncate()This method returns the integer after discarding fraction digitsImplementation of methods : Dart void main() { double number = -12.75; int intNumber = 15; // abs() - Returns absolute value print('Absolute Value: ${number.abs()}'); // Output: 12.75 // ceil() - Returns the smallest integer // greater than or equal to the number print('Ceiling Value: ${number.ceil()}'); // Output: -12 // floor() - Returns the largest integer // less than or equal to the number print('Floor Value: ${number.floor()}'); // Output: -13 // compareTo() - Compares the number // with another number print('Compare To (10): ${number.compareTo(10)}'); // Output: -1 (since number < 10) // remainder() - Returns the remainder // after division print('Remainder when divided by 5: ${number.remainder(5)}'); // Output: -2.75 // round() - Rounds the number to // the nearest integer print('Rounded Value: ${number.round()}'); // Output: -13 // toDouble() - Converts int to double print('Integer to Double: ${intNumber.toDouble()}'); // Output: 15.0 // toInt() - Converts double to int print('Double to Integer: ${number.toInt()}'); // Output: -12 // toString() - Converts number to String print('Number as String: ${number.toString()}'); // Output: "-12.75" // truncate() - Removes the decimal // part, returning an integer print('Truncated Value: ${number.truncate()}'); // Output: -12 } Output:Absolute Value: 12.75Ceiling Value: -12Floor Value: -13Compare To (10): -1Remainder when divided by 5: -2.75Rounded Value: -13Integer to Double: 15Double to Integer: -12Number as String: -12.75Truncated Value: -12Some try-error for numExample 1: Using num to Store Different Number Types Dart void main(){ int x = 10; // Error: A value of type 'double' // can't be assigned to a variable // of type 'int'. x = 20.5; num y = 10; // No Error y = 10.5; } That means we can assign an int to a double, but assigning a double to an int directly will cause an error. You need to use .toInt().Example 2: Assigning Values Between int and double Dart void main(){ double y = 10; // We can store the int value into the double data type but // we can't store double value in int type. y = 10.5; } We can store the int value into the double data type but we can't store double value in int type.Dart uses the int type for whole numbers and the double type for floating-point numbers. The num type serves as the parent class for both int and double, which provides flexibility in number storage. Dart also offers a variety of powerful properties and methods to work with numbers efficiently. You can convert strings to numbers by using the num.parse() method. Comment More infoAdvertise with us Next Article Strings in Dart S SHUBHAMSINGH10 Follow Improve Article Tags : Dart Dart-basics Dart Data-types Similar Reads Dart Tutorial Dart is an open-source general-purpose programming language developed by Google. It supports application development on both the client and server side. However, it is widely used for the development of Android apps, iOS apps, IoT(Internet of Things), and web applications using the Flutter Framework 7 min read BasicsIntroduction to Dart Programming LanguageDart is an open-source programming language originally developed by Google. It is designed for both server-side and client-side development. The Dart SDK includes its compiler, the Dart VM, as well as a utility called dart2js, which converts Dart scripts into JavaScript. This makes it possible to ru 4 min read Dart SDK InstallationTo do a lot of interesting programming stuff using the Dart programming language, we have to install the Dart SDK. Dart SDK is a pre-compiled version so we have to download and extract it only. In this article, we will learn how to perform Dart SDK Download.Table of ContentInstall Dart SDK in Window 4 min read Dart - CommentsIn every programming language comments play an important role for a better understanding of the code in the future or by any other programmer. Comments are a set of statements that are not meant to be executed by the compiler. They provide proper documentation of the code. Types of Dart CommentsDart 2 min read Dart - VariablesA variable name is the name assigned to the memory location where the user stores the data and that data can be fetched when required with the help of the variable by calling its variable name. Various types of variables are used to store the data. The kind which will be used to store data depends u 5 min read Operators in DartThe operators are special symbols used to perform certain operations on operands. Dart has numerous built-in operators that can be utilized for various functions; for example, '+' is used to add two operands. Operators are designed to execute operations on one or two operands. Precedence Table of Op 11 min read Dart - Standard Input OutputIn Dart programming language, you can take standard input from the user through the console via the use of the .readLineSync() function. To take input from the console you need to import a library, named dart:io from the libraries of Dart.Stdin ClassThis class allows the user to read data from stand 3 min read Data TypesDart - Data TypesLike other languages (C, C++, Java), whenever a variable is created, each variable has an associated data type. In Dart language, there are the types of values that can be represented and manipulated in a programming language. In this article, we will learn about Dart Programming Language Data Types 8 min read Basics of Numbers in DartLike other languages, Dart Programming also supports numerical values as Number objects. The number in Dart Programming is the data type that is used to hold the numeric value. Dart numbers can be classified as: int (Integer) The int data type is used to represent whole numbers.Declaring Integer in 6 min read Strings in DartA Dart string is a sequence of UTF-16 code units. With the same rule as that of Python, you can use either single or double quotes to create a string. The string starts with the datatype String or Var : String string = "I love GeeksforGeeks";var string1 = 'GeeksforGeeks is a great platform for upgra 6 min read Dart - SetsSets in Dart is a special case in List, where all the inputs are unique i.e. it doesn't contain any repeated input. It can also be interpreted as an unordered array with unique inputs. The set comes into play when we want to store unique values in a single variable without considering the order of t 6 min read Dart Programming - MapIn Dart programming, Maps are dictionary-like data types that exist in key-value form (known as lock-key). There is no restriction on the type of data that goes in a map data type. Maps are very flexible and can mutate their size based on the requirements. However, it is important to note that all l 7 min read Queues in DartDart also provides the user to manipulate a collection of data in the form of a queue. A queue is a FIFO (First In First Out) data structure where the element that is added first will be deleted first. It takes the data from one end and removes it from the other end. Queues are useful when you want 3 min read Data Enumeration in DartEnumerated types (also known as enumerations or enums) are primarily used to define named constant values. The enum keyword is used to define an enumeration type in Dart. The use case of enumeration is to store finite data members under the same type definition. Declaring enumsenum variable_name{ // 3 min read Control FlowSwitch Case in DartIn Dart, switch-case statements are a great tool for managing multiple conditions in a clean and organized way. They serve as a more efficient alternative to lengthy if-else chains, making your code easier to read and maintain.Syntax:switch (expression) { case value1: // Body of value1 break; case v 2 min read Dart - LoopsA looping statement in Dart or any other programming language is used to repeat a particular set of commands until certain conditions are not completed. There are different ways to do so. They are: for loopfor... in loopfor each loopwhile loopdo-while loopfor loopThe for loop in Dart is a powerful c 4 min read Dart - Loop Control Statements (Break and Continue)Dart supports two types of loop control statements: Break Statement Continue StatementBreak StatementThis statement is used to break the flow of control of the loop i.e. if it is used within a loop then it will terminate the loop whenever encountered. It will bring the flow of control out of the nea 4 min read Labels in DartMost people, who have programmed in C programming language, are aware of goto and label statements which are used to jump from one point to another unlike Java, Dart also doesn't have any goto statements but indeed it has labels that can be used with continue and break statements and help them to ta 2 min read Key FunctionsDart - Anonymous FunctionsAn anonymous function in Dart is like a named function but they do not have names associated with it. An anonymous function can have zero or more parameters with optional type annotations. An anonymous function consists of self-contained blocks of code and that can be passed around in our code as a 2 min read Dart - main() FunctionThe main() function is a predefined method in Dart. It is the most important and mandatory part of any dart program. Any dart script requires the main() method for its execution. This method acts as the entry point for any Dart application. It is responsible for executing all library functions, user 2 min read Dart - Common Collection MethodsList, Set, and Map share common functionalities found in many collections. Some of this common functionality is defined by the Iterable class, which is implemented by both List and Set.1. isEmpty() or isNotEmptyUse isEmpty or isNotEmpty to check whether a list, set, or map has items or not.Example:D 2 min read How to Exit a Dart Application Unconditionally?The exit() method exits the current program by terminating the running Dart VM. This method takes a status code. A non-zero value of status code is generally used to indicate abnormal termination. This is a similar exit in C/C++, Java. This method doesn't wait for any asynchronous operations to term 2 min read Dart - Getters and SettersGetters and Setters, also called accessors and mutators, allow the program to initialize and retrieve the values of class fields respectively. Getters or accessors are defined using the get keyword.Setters or mutators are defined using the set keyword.A default getter/setter is associated with every 3 min read Dart - Classes And ObjectsDart is an object-oriented programming language, so it supports the concept of class, object, etc. In Dart, we can define classes and objects of our own. We use the class keyword to do so. Dart supports object-oriented programming features like classes and interfaces.Let us learn about Dart Classes 4 min read Object-Oriented ProgrammingDart - this keywordthis keyword represents an implicit object pointing to the current class object. It refers to the current instance of the class in a method or constructor. The this keyword is mainly used to eliminate the ambiguity between class attributes and parameters with the same name. When the class attributes 2 min read Dart - Static KeywordThe static keyword is used for the memory management of global data members. The static keyword can be applied to the fields and methods of a class. The static variables and methods are part of the class instead of a specific instance. The static keyword is used for a class-level variable and method 3 min read Dart - Super and This keywordSuper Keyword in DartIn Dart, the super keyword is used to refer immediate parent class object. It is used to call properties and methods of the superclass. It does not call the method, whereas when we create an instance of subclass than that of the parent class is created implicitly so super keywor 4 min read Dart - Concept of InheritanceIn Dart, one class can inherit another class, i.e. dart can create a new class from an existing class. We make use of extend keyword to do so.Terminology: Parent Class: It is the class whose properties are inherited by the child class. It is also known as a base class or super class.Child Class: It 5 min read Instance and class methods in DartDart provides us with the ability to create methods of our own. The methods are created to perform certain actions in class. Methods help us to remove the complexity of the program. It must be noted that methods may or may not return any value, and also, they may or may not take any parameter as inp 3 min read Method Overriding in DartMethod overriding occurs in Dart when a child class tries to override the parent class's method. When a child class extends a parent class, it gets full access to the methods of the parent class and thus it overrides the methods of the parent class. It is achieved by re-defining the same method pres 3 min read Getter and Setter Methods in DartGetter and Setter methods are class methods used to manipulate the data of class fields. Getter is used to read or get the data of the class field, whereas setter is used to set the data of the class field to some variable. The following diagram illustrates a Person class that includes: A private va 2 min read Abstract Classes in DartAn abstract class in Dart is defined as a class that contains one or more abstract methods (methods without implementation). To declare an abstract class, we use the abstract keyword. It's important to note that a class declared as abstract may or may not include abstract methods. However, if a clas 4 min read Dart - Builder ClassIn Flutter, each widget has an associated build method responsible for rendering the UI. The Flutter framework automatically provides a BuildContext parameter to the build method.Widget build ( BuildContext context )Flutter takes care that there need not be any Widget apart from the build that needs 4 min read Concept of Callable Classes in DartDart allows the user to create a callable class which allows the instance of the class to be called as a function. To allow an instance of your Dart class to be called like a function, implement the call() method. Syntax :class class_name { ... // class content return_type call ( parameters ) { ... 4 min read Interface in DartThe interface in the dart provides the user with the blueprint of the class, which any class should follow if it interfaces that class, i.e., if a class inherits another, it should redefine each function present inside an interfaced class in its way. They are nothing but a set of methods defined for 3 min read Dart - extends Vs with Vs implementsAll developers working with Dart for application development using the Flutter framework regularly encounter different usages of the implements, extends, and keywords. In Dart, one class can inherit another class, i.e. , Dart can create a new class from an existing class. We make use of keywords to 4 min read Dart - Date and TimeA DateTime object is a point in time. The time zone is either UTC or the local time zone. Accurate date-time handling is required in almost every data context. Dart has the marvelous built-in classes for date time and duration in dart:core. Key Uses of DateTime in Dart:Comparing and Calculating Date 3 min read Using await async in DartThe async and await approaches in Dart are very similar to other languages, which makes it a comfortable topic to grasp for those who have used this pattern before. However, even if you donât have experience with asynchronous programming using async/await, you should find it easy to follow along her 4 min read Dart UtilitiesHow to Combine Lists in Dart?The List data type in Dart programming is similar to arrays in other programming languages. A list is used to represent a collection of objects. It is an ordered group of objects. The core libraries in Dart are responsible for the existence of the List class, its creation, and manipulation. There ar 3 min read Dart - Finding Minimum and Maximum Value in a ListIn Dart, we can find the minimum and maximum valued element present in the given list in seven ways:Use the for loop to find the largest and smallest elements.Use the sort function to find the largest and smallest elements.Using forEach loop to find the largest and smallest element.Using only the re 5 min read Dart - Splitting of StringIn Dart splitting of a string can be done with the help split string function in the dart. It is a built-in function use to split the string into substring across a common character.Syntax:string_name.split(pattern)This function splits the string into substrings across the given pattern and then sto 1 min read Dart ProgramsDart - Sort a ListThe List data type is similar to arrays in other programming languages. A list is used to represent a collection of objects. It is an ordered group of objects. The core libraries in Dart are responsible for the existence of the List class, its creation, and manipulation. Sorting of the list depends 2 min read Dart - String toUpperCase() Function with ExamplesThe string toUpperCase() method converts all characters of the string into an uppercase letter. The string toUpperCase() function returns the string after converting all characters of the string into the uppercase letter. Syntax: Str.toUpperCase()Parameter: The string toUpperCase() function doesn't 1 min read Dart - Convert All Characters of a String in LowercaseWith the help of the toLowerCase() method in the string will convert all the characters in a string in lowercase.Syntax: String.toLowerCase() Return: string Image Representation: Example 1: Dart// main function start void main() { // initialise a string String st = "GEEKSFORGEEKS"; // print the stri 1 min read How to Replace a Substring of a String in Dart?To replace all the substrings of a string, we make use of the replaceAll method in Dart. This method replaces all the substrings in the given string with the desired substring. Returns a new string in which the non-overlapping substrings matching from (the ones iterated by from.allMatches(this Strin 2 min read How to Check String is Empty or Not in Dart (Null Safety)?We can check a string is empty or not by the String Property isEmpty. If the string is empty then it returns True if the string is not empty then it returns False.Syntax: String.isEmpty Return : True or False.Image Representation: Example 1:Dart// main function start void main() { // initialise a st 1 min read Exception Handling in DartAn exception is an error that occurs inside the program. When an exception occurs inside a program, the normal flow of the program is disrupted, and it terminates abnormally, displaying the error and exception stack as output. So, an exception must be taken care of to prevent the application from te 3 min read Assert Statements in DartAs a programmer, it is very necessary to make an errorless code is very necessary and to find the error is very difficult in a big program. Dart provides the programmer with assert statements to check for the error. The assert statement is a useful tool to debug the code, and it uses a Boolean condi 3 min read Fallthrough Condition in DartFall through is a type of error that occurs in various programming languages like C, C++, Java, Dart ...etc. It occurs in switch-case statements where when we forget to add break statement and in that case flow of control jumps to the next line. "If no break appears, the flow of control will fall th 3 min read Concept of Isolates in DartDart was traditionally designed to create single-page applications. We also know that most computers, even mobile platforms, have multi-core CPUs. To take advantage of all those cores, developers traditionally use shared-memory threads running concurrently. However, shared-state concurrency is error 2 min read Advance ConceptsDart - CollectionsCollections are groups of objects that represent a particular element. The dart::collection library is used to implement the Collection in Dart. There are a variety of collections available in Dart.Dart CollectionThere are 5 Interfaces that we have in the Dart Collection, as mentioned below:ListQueu 7 min read Dart - Basics of PackagesThe package is a set of Dart programs organized in an independent, reusable unit. Dart packages donât include compiled code. The code is compiled when the app is built or run. Sample data may be included optionally by the package author. Dart comes with core libraries (not packages), automatically a 2 min read Dart - String codeUnits PropertyThe string property codeunits in Dart programming language returned the list of UTF-16 code of the characters of a string. It is very useful string properties to directly find UTF-16 code units. Syntax: String.codeUnits Returns: a list of UTF-16 code units Example 1: Dart // main function start vo 1 min read HTML Document Object Model and Dart ProgrammingWe all know that dart is a type of javascript. So we can manipulate data inside HTML pages with the help of dart in a similar fashion as we can do with javascript. In HTML DOM (Document Object Model) every webpage is on a window, so it is considered as an object. The hierarchical model that follows 3 min read Like