Options
All
  • Public
  • Public/Protected
  • All
Menu

External module "math/base/special/truncb/docs/types/index.d"

Index

Functions

Functions

Export assignment truncb

  • truncb(x: number, n: number, b: number): number
  • Rounds a numeric value to the nearest multiple of \(b^n\) toward zero.

    Notes

    • Due to floating-point rounding error, rounding may not be exact.

    Parameters

    • x: number

      input value

    • n: number

      integer power

    • b: number

      base

    Returns number

    rounded value

    Example

    // Round a value to 4 decimal places:
    var v = truncb( 3.141592653589793, -4, 10 );
    // returns 3.1415

    Example

    // If n = 0 or b = 1, `truncb` behaves like `trunc`:
    var v = truncb( 3.141592653589793, 0, 2 );
    // returns 3.0

    Example

    // Round a value to the nearest multiple of two toward zero:
    var v = truncb( 5.0, 1, 2 );
    // returns 4.0