Skip to content

[Feature request]: Enable rounding to zero #301

@GreenImp

Description

@GreenImp

Feature request and related problem

As mentioned in the docs, the round() function always rounds half away from zero.

Sometimes we want to round towards zero instead:

// positive numbers
3.7   -> 3
4.5   -> 4
12.3  -> 12

// negative numbers
-2.9  -> 2
-3.5  -> -3
-65.2 -> -65

This was originally mention in #227

The Javascript Math.trunc() method achieves this.
And MathJs (The library used internally by this library) has a fix() method, which also does this, but has the benefit of also allowing you to specify the number of decimals.

Suggested solution

I propose that we enable a fix() function, which uses the MathJs fix() function, and also an alias for it of trunc(), so those familiar with that method can use it.

Alternatives

No response

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions