Arithmetic operators (+, -, *, /, %, exponentiation, and floor division) seem simple, but their behavior differs across languages. Using them without understanding these differences can silently break production systems — especially in finance, analytics, or dashboards.
In this guide, we’ll show real, practical examples for each language demonstrating all common operators in action.
Before we step into the practical example, let me show you the list of available arithmetic operators across various platforms.
Operator and Meaning
- + →Addition
- - → Subtraction
- * →Multiplication
- / →Division
- % →Modulus (Remainder)
Some languages also include:
- ** → Exponentiation (Python)
- ^ → Exponent (R)
- %% → Modulus (R)
- // → Floor division (Python)
SQL — Payroll Calculations
The following SQL query performs arithmetic addition, subtraction, multiplication, division, and modulus on the employees table. Using these arithmetic operators, it calculates the total salary with/without deductions, annual salary, etc.
SELECT emp_id,
salary + bonus AS TotalSalary,
salary - deductions AS ActualSalary,
salary * 12 AS AnnualSalary,
salary / 2 AS HalfSalary,
salary % 100 AS LeftoverChange
FROM employees;
Learn more: Arithmetic Operators in SQL
MySQL — Sales Data Example
Here we handle product sales. + adjusts units for returns, * calculates total revenue, / finds revenue in hundreds, which is good for easier reporting, % finds leftover cents, and POW squares revenue for analytics. This demonstrates MySQL arithmetic operators for practical sales metrics.
SELECT product_id,
sold_units + returns AS adjusted_units,
sold_units * price AS total_revenue,
total_revenue / 100 AS revenue_in_hundreds,
total_revenue % 100 AS remainder_cents,
POW(total_revenue, 2) AS squared_revenue
FROM sales;
Learn More: Arithmetic Operators in MySQL
Python — Finance Dashboard
The following example is a complete finance calculation example. In Python, it is common to sum sales and bonuses to get total revenue, divide by length for average, split revenue in half, check remainders with %, square total revenue with **, and perform floor division with //.
sales = [1500, 2000, 1800, 2200]
bonus = [100, 150, 120, 200]
total_revenue = sum(sales) + sum(bonus)
avg_revenue = total_revenue / len(sales)
half_revenue = total_revenue / 2
remainder = total_revenue % 3
growth_squared = total_revenue ** 2
floor_div = total_revenue // 4
print(total_revenue, avg_revenue, half_revenue, remainder, growth_squared, floor_div)
Learn More: Python Arithmetic Operators
R — Analytics & Vectorized Operations
R handles vectors easily, and this example uses vectors to demonstrate the arithmetic operators. We add sales and bonus element-wise, subtract a deduction for net revenue, multiply for annual projection, divide for half-year values, check remainder with %%, square totals with ^, and use %/% for integer division.
sales <- c(1500, 2000, 1800, 2200)
bonus <- c(100, 150, 120, 200)
total <- sales + bonus
net <- total - 50
annual <- total * 12
half_year <- total / 2
remainder <- total %% 3
squared <- total ^ 2
floor_div <- total %/% 4
data.frame(total, net, annual, half_year, remainder, squared, floor_div)
Learn More: R Arithmetic Operators
C — Embedded or High-Performance Systems
In C, we add revenue and bonus, subtract a fixed cost for net, multiply for annual totals, divide for half using float to preserve decimals, % gives the remainder, integer division truncates, and squaring shows growth.
Try replacing the revenue and bonus values,and also try changing the data type.
#include <stdio.h>
int main() {
int revenue = 4520, bonus = 300;
int total = revenue + bonus;
int net = total - 200;
int annual = total * 12;
float half = total / 2.0;
int remainder = total % 3;
int floor_div = total / 4;
int squared = total * total;
printf("Total: %d, Net: %d, Annual: %d, Half: %.2f, Remainder: %d, FloorDiv: %d, Squared: %d\n",
total, net, annual, half, remainder, floor_div, squared);
return 0;
}
Learn Moore: Arithmetic Operators in C
C# — Billing / Subscription Logic
C# is similar to C. + adds revenue and bonus, - subtracts fixed costs, * multiplies for annual total, / divides revenue, % gives remainder, / on integers truncates, and Math.Pow squares totals.
int revenue = 4520;
int bonus = 300;
int total = revenue + bonus;
int net = total - 200;
int annual = total * 12;
double half = total / 2.0;
int remainder = total % 3;
int floorDiv = total / 4;
double squared = Math.Pow(total, 2);
Console.WriteLine($"Total: {total}, Net: {net}, Annual: {annual}, Half: {half}, Remainder: {remainder}, FloorDiv: {floorDiv}, Squared: {squared}");
Java — Accounting Systems
Java follows the same logic as C#. Addition, subtraction, multiplication, and division behave as expected. % finds remainders and Math.pow handles squaring for growth or analysis.
public class RevenueExample {
public static void main(String[] args) {
int revenue = 4520;
int bonus = 300;
int total = revenue + bonus;
int net = total - 200;
int annual = total * 12;
double half = total / 2.0;
int remainder = total % 3;
int floorDiv = total / 4;
double squared = Math.pow(total, 2);
System.out.println("Total: " + total + ", Net: " + net + ", Annual: " + annual +
", Half: " + half + ", Remainder: " + remainder +
", FloorDiv: " + floorDiv + ", Squared: " + squared);
}
}
For more information: Java Arithmetic Operators
JavaScript — Frontend Dashboards
In JavaScript, + adds revenue and bonus, - subtracts costs, * multiplies for annual totals, / divides, % finds remainder, Math.floor performs floor division, and ** squares totals for calculations. This example works well for dashboards.
let revenue = 4520;
let bonus = 300;
let total = revenue + bonus;
let net = total - 200;
let annual = total * 12;
let half = total / 2;
let remainder = total % 3;
let floorDiv = Math.floor(total / 4);
let squared = total ** 2;
console.log({ total, net, annual, half, remainder, floorDiv, squared });
For more: Arithmetic Operators in JavaScript
Top comments (0)