# math.calculate()

The `math.calculate()` function performs value and operand calculation by using a given operator `+` addition, `-` subtraction, `*` multiplication, `/` division of `string` type.

{% code lineNumbers="true" %}

```scss
// Sass.
@use 'sass:list';
@use 'sass:meta';

// The `math.calculate()` function.
@function calculate($operations...) {
  @each $value, $operator,
    $operand in if(list.length($operations) == 3, ($operations), $operations)
  {
    @if $value and $operand {
      @if $operator == '+' {
        @return calc($value + $operand);
      } @else if $operator == '-' {
        @return calc($value - $operand);
      } @else if $operator == '*' {
        @return calc($value * $operand);
      } @else if $operator == '/' {
        @return calc($value / $operand);
      }
    }
  }
  @return null;
}
```

{% endcode %}

{% embed url="<https://github.com/angular-package/sass/blob/main/math/_math.calculate.function.scss>" %}

### Parameters

#### **`$operations...`**

Arbitrary values in order (value, operator, operand) to perform calculation.

### Return

The return value is calculated `number` or CSS function [`calc()`](https://developer.mozilla.org/en-US/docs/Web/CSS/calc) with a specified calculation.

## Examples

```scss
// Use.
@use '@angular-package/sass/math';

// Examples.
// number
@debug math.calculate(15 '+' 13); // 28
@debug math.calculate(15 '-' 12); // 3
@debug math.calculate(55 '*' 17); // 935
@debug math.calculate(42 '/' 14); // 3
@debug math.calculate(15, '+', 13); // 28

// var()
@debug math.calculate(15, '+', var(--age)); // calc(15 + var(--age))
@debug math.calculate(var(--age), '+', var(--age)); // calc(var(--age) + var(--age))

```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.angular-package.dev/sass/math/math.calculate.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
