# Math Parser (/placeholders/parsers/math)



## Usage [#usage]

To use the parser, insert the following syntax in your text:

`{math(parameter):expression}`

The parameter is optional. If omitted, the result will be returned as a decimal number.

## Operators [#operators]

### Arithmetic Operators [#arithmetic-operators]

* `+` - Addition
* `-` - Subtraction (also supports unary minus for negative numbers)
* `*` - Multiplication
* `/` - Division
* `%` - Modulo (remainder after division)
* `^` - Exponentiation (power)

### Operator Precedence [#operator-precedence]

Operators are evaluated in the following order (highest to lowest):

1. `^` (exponentiation, right-associative)
2. `*`, `/`, `%` (multiplication, division, modulo, left-associative)
3. `+`, `-` (addition, subtraction, left-associative)

## Parameters [#parameters]

### Fixed Decimal Places [#fixed-decimal-places]

* `fixed=N` - Formats the result with N decimal places (0-10)
  * Example: `{math(fixed=2):10/3}` → `3.33`

### Integer Truncation [#integer-truncation]

* `int` - Returns the integer part of the result (truncates decimal portion)
  * Example: `{math(int):10/3}` → `3`

## Examples [#examples]

### Basic Arithmetic [#basic-arithmetic]

* `{math:2+2}` → `4`
* `{math:10-5}` → `5`
* `{math:3*4}` → `12`
* `{math:15/3}` → `5`
* `{math:17%5}` → `2`
* `{math:2^3}` → `8`

### Complex Expressions [#complex-expressions]

* `{math:2+3*4}` → `14` (multiplication before addition)
* `{math:(2+3)*4}` → `20` (parentheses change order)
* `{math:10/3+5}` → `8.333333333333334`
* `{math:2^3^2}` → `512` (right-associative: 2^(3^2))

### Negative Numbers [#negative-numbers]

* `{math:-5+3}` → `-2`
* `{math:(-5)*2}` → `-10`
* `{math:10+-3}` → `7`

### With Parameters [#with-parameters]

* `{math(fixed=2):10/3}` → `3.33`
* `{math(fixed=0):10/3}` → `3`
* `{math(int):10/3}` → `3`
* `{math(fixed=4):2^8}` → `256.0000`

### Nested Expressions [#nested-expressions]

* `{math:(5+3)*(2+1)}` → `24`
* `{math:((10-2)/2)^2}` → `16`
* `{math:100/(5*2)}` → `10`

## Variable Support [#variable-support]

You can use variables within mathematical expressions:

* `{math:{currentTime}+604800000}` → Adds 7 days to the current timestamp
* `{math:{guild.memberCount}/2}` → Calculates half of guild member count

Note: The parser supports decimal numbers, parentheses for grouping, and follows standard mathematical operator precedence. Division by zero, invalid expressions, and results exceeding safety limits will return no output.
