Question #137EasyGeneral

What is BODMAS rules for calculation ?

Answer

Overview

BODMAS (also written as PEMDAS in the US) is the order of operations rule that defines the sequence in which mathematical operations must be performed in an expression.


BODMAS Full Form

LetterOperationExample
BBrackets
text
(2 + 3)
OOf (Powers/Exponents)
text
2³ = 8
DDivision
text
10 ÷ 2
MMultiplication
text
3 × 4
AAddition
text
5 + 3
SSubtraction
text
9 - 4

Rule

Evaluate in this order: Brackets → Of → Division → Multiplication → Addition → Subtraction

Note: Division and Multiplication have equal priority (left to right). Same for Addition and Subtraction.


Examples

text
BODMAS Example 1:
2 + 3 × 4
= 2 + 12     (Multiplication first)
= 14

BODMAS Example 2:
(2 + 3) × 4
= 5 × 4      (Brackets first)
= 20

BODMAS Example 3:
10 ÷ 2 + 3 × 4 - 1
= 5 + 12 - 1  (Division and Multiplication first)
= 16          (Addition and Subtraction left to right)

BODMAS in Dart

dart
void main() {
  // Dart follows standard math order of operations
  print(2 + 3 * 4);            // 14 (not 20 — multiplication first)
  print((2 + 3) * 4);          // 20 (brackets override)
  print(10 / 2 + 3 * 4 - 1);  // 16.0
  print(10 ~/ 3);              // 3 (integer division)

  // Order of operations in expressions
  double result = 5 + 3 * 2 - 8 / 4;
  // = 5 + 6 - 2   (mult and div first)
  // = 9.0
  print(result); // 9.0

  // Exponent using math library
  import 'dart:math';
  print(pow(2, 3));  // 8 (2³)
  print(pow(3, 2));  // 9 (3²)
}

Common Mistakes

text
❌ Wrong:  2 + 3 × 4 = 20  (adding first)
✅ Right:  2 + 3 × 4 = 14  (multiplying first)

❌ Wrong:  20 / 5 × 2 = 2  (dividing right side first)
✅ Right:  20 / 5 × 2 = 8  (left to right: 20/5=4, then 4×2=8)

Remember: BODMAS ensures everyone gets the same answer for the same mathematical expression. Always use parentheses in code when in doubt — it makes intent explicit and avoids subtle bugs.