solarnetwork-api-core
    Preparing search index...

    Function displayUnitsForScale

    • Get an appropriate display unit for a given base unit and scale factor.

      Use this method to render scaled data value units. Typically you would first call Util.Numbers.displayScaleForValue, passing in the largest expected value in a set of data, and then pass the result to this method to generate a display unit for the base unit for that data.

      For example, given a base unit of W (watts) and a maximum data value of 10000:

      const displayScale = displayScaleForValue(10000);
      const displayUnit = displayUnitForScale('W', displayScale);

      The displayUnit result in that example would be kW.

      Parameters

      • baseUnit: string

        the base unit, for example W or Wh

      • scale: number

        the unit scale, which must be a recognized SI scale, such as 1000 for k

      Returns string

      the display unit value