Rouge Documentation Help

Working with numbers

Previously, we only learned how to create numbers in memory and store them in variables. Now, let us take a look at what we can actually do with them.

Rational numbers

At this point, we have only taken a look at how to create integers (positive whole numbers). However, in Rouge you can actually work with rational numbers by using a decimal point and/or positive or negative signs. When you specify a number without a sign, it will always be positive. You are not limited to a specific number of fractional digits.

price = 3.99 debt = -400.87 distance = 367.4567

Numeric operations

Numbers can be added, subtracted, multiplied or divided with the following operators. An operator is a mathematical operation represented by a symbol. An operator takes two numbers into account and calculates a result from them. These operations should feel intuitive to you because the same notation is used in math. We will also take a look at an operation similar to division, called modulo, and show you how different operators take precedence over others.

Addition

2 + 1.1

Output:

3.1

Subtraction

2 - 1

Output:

1

Multiplication

2 * 3.5

Output:

7

Division

6 / 3

Output:

2

Modulo

The above operations are self-explanatory. However, if you never programmed before, you might not be familiar with the modulo operator. The modulo operator (%) performs a division, but instead of yielding the result of the division, it yields its remainder.

7 % 3

Output:

1

Operator precedence

In the examples above, we looked at each operation in isolation. However, these operations can be chained as well.

7 * 3 + 1

Output:

22

As you can see in the example, the multiplication is evaluated before the addition. Mathematical operations in Rouge follow the "dot before line" rule, meaning that multiplication, division, and modulo are evaluated before addition and subtraction. Should you wish to override the operator precedence, you can use parenthesis.

7 * (3 + 1)

Output:

28

Numeric operations and variables

Previously, when you were introduced to variables, you learned that you can create a value by spelling out a number. This value can be assigned to a variable. The numeric operations shown above also produce a value and can therefore also be assigned to a variable.

result = 7 * (3 + 1) result

Output:

28
Last modified: 07 January 2026