numbro icon indicating copy to clipboard operation
numbro copied to clipboard

Format with abbreviations not work

Open minikinl opened this issue 1 year ago • 1 comments

Problem

Run this code at console of numbro website:

numbro(1234000).format({
  output: "number",
  forceAverage: "million",
  abbreviations: {
        thousand: "K",
        million: "M",
        billion: "B",
        trillion: "T"
    },
})

// output: 1m

Expect Behavior

The outputs should be 1M

Description

According to the description of the code:

https://github.com/BenjaminVanRyseghem/numbro/blob/cac205533ccdb6013a855f6aa6467acd04dae269/src/validating.js#L154

There is an option named abbreviations which can be used in config abbr of thousand | million | ....

Debug

image

Within the formatting.js#formatNumber() function,the providedFormat.abbreviations was ignored to computed the average abbreviation. ONLY globalState.currentAbbreviations was used.

Solution

// maybe this will work...
abbreviations: Object.assign({}, state.currentAbbreviations(), providedFormat.abbreviations),

minikinl avatar May 12 '23 03:05 minikinl

Thanks for the report. I'll look into it as soon as I can :smile:

BenjaminVanRyseghem avatar May 12 '23 06:05 BenjaminVanRyseghem