mathFunction
In Dart, you can perform various mathematical operations using built-in
functions and operators. Here are some common mathematical operations you
can perform in Dart:
To use math in dart, you must import 'dart:math';.
Basic Arithmetic Operations:
Dart supports the basic arithmetic operations, including addition, subtraction, multiplication, and division, using operators like +, -, *, and /.
void main() {
int num1 = 10;
int num2 = 5;
int sum = num1 + num2; // Addition
int difference = num1 - num2; // Subtraction
int product = num1 * num2; // Multiplication
double quotient = num1 / num2; // Division
print('Sum: $sum');
print('Difference: $difference');
print('Product: $product');
print('Quotient: $quotient');
}
Modulus Operator:
The modulus operator % calculates the remainder of a division operation.
Mathematical Functions:
Dart provides mathematical functions like sqrt, pow, sin, cos, and tan in the dart:math library for more advanced calculations.
Random Numbers:
To generate random numbers, you can use the Random class from the dart:math library.
These are some of the fundamental mathematical operations and functions available in Dart. Depending on your needs, you can perform a wide range of mathematical calculations in your Dart programs.
Last updated