Function scalePercentages

Scales an input percentage to a new percentage range.

If you have an input percentage (0-1), scalePercentageOutput maps it to an output percentage of outMin-outMax.

import { scalePercentages } from 'https://unpkg.com/ixfx/dist/data.js';

// Scales 50% to a range of 0-10%
scalePercentages(0.5, 0, 0.10); // 0.05 - 5%

An error is thrown if any parameter is outside of percentage range. This added safety is useful for catching bugs. Otherwise, you could just as well call scale(percentage, 0, 1, outMin, outMax).

If you want to scale some input range to percentage output range, just use scale:

import { scale } from 'https://unpkg.com/ixfx/dist/data.js';

// Yields 0.5
scale(2.5, 0, 5);
  • Parameters

    • percentage: number

      Input value, within percentage range

    • outMin: number

      Output minimum, between 0-1

    • outMax: number = 1

      Output maximum, between 0-1

    Returns number

    Scaled value between outMin-outMax.