HexLibraryHexLibrary
</> HexCodeSign inSign up
PythonJavaScriptTypeScriptCC++JavaPHPGoRustRubyBashSQLLuaPerlCOBOLPascalDelphiFortranDartSwiftC#JuliaGroovyRElixirHaskellKotlinScalaClassic ASPClipperMS-DOS
LESSONS
Introduction to DartVariablesData TypesOperatorsStringsListsConditions (if / else)Loops (for / while)Functions
REFERENCE
📖 Overview
🖥️ Output
📦 Variables & Types
🔢 Numbers & Math
Math operators.abs() / .round()sqrt() / pow() (dart:math)
✍️ String
📚 List & Map
🔀 Condition & Loop
🧩 Function
Dart›REFERENCE›Numbers & Math
🔢

Numbers & Math

Operators and dart:math functions.

CommandDescription
Math operatorsFour basic operations, integer division, and remainder.
.abs() / .round()Absolute value and rounding.
sqrt() / pow() (dart:math)Square root and powers (math library).

Math operators

Try it yourself →

Four basic operations, integer division, and remainder.

Syntax

+  -  *  /  ~/  %

Description

/ always returns a decimal (double). Use ~/ for integer division. % gives the remainder (commonly used in even/odd checks).

Example

void main() {
  print(7 + 3);
  print(7 / 2);
  print(7 ~/ 2);
  print(7 % 2);
}

Expected output

10
3.5
3
1

When to use?

Calculations, even/odd check (number % 2).

Common mistakes

  • ⚠️ / returns a decimal; use ~/ if you want an integer result.

.abs() / .round()

Try it yourself →

Absolute value and rounding.

Syntax

number.abs()  //  number.round()

Description

abs strips the sign (absolute value). round rounds to the nearest integer. floor rounds down, and ceil rounds up.

Example

void main() {
  print((-5).abs());
  print(3.7.round());
  print(3.2.ceil());
}

Expected output

5
4
4

When to use?

Calculating differences, rounding money/scores.

sqrt() / pow() (dart:math)

Try it yourself →

Square root and powers (math library).

Syntax

import 'dart:math';  sqrt(x)  pow(x, y)

Description

Square root (sqrt), power (pow), pi, and random numbers are inside dart:math. You must write import 'dart:math'; before using them.

Example

import 'dart:math';
void main() {
  print(sqrt(81));
  print(pow(2, 10));
}

Expected output

9.0
1024

When to use?

Geometry, statistics, exponential calculations.

Common mistakes

  • ⚠️ Forgetting to write import 'dart:math'; causes an error.
HexLibraryHexLibrary

Learn programming more clearly. Every command is explained line by line with colors, reinforced with runnable exercises, test your code instantly — all in one place, free.

Learn

  • Home
  • Languages & Lessons
  • HexCode

Company

  • About
  • Contact

Legal

  • Privacy Policy
  • Terms of Use

Other Projects

  • HexToolz
  • Free Service Manuals
© 2026 HexLibrary · The clearest way to learn code