NumberFormatter
Type class
NumberFormatter class. Formats numbers according to specified formats.
Sources
NumberFormatter can be used (imported) via one of the following packages.
/** * Import from: "core.ts" * Use like: am4core.NumberFormatter */import * as am4core from "@amcharts/amcharts4/core";/** * Include via: <script src="core.js"></script> * Access items like: am4core.NumberFormatter */Inheritance
NumberFormatter extends BaseObject.
NumberFormatter is not extended by any other symbol.
Properties
bigNumberPrefixesType
INumberSuffix[]Prefixes for big numbers.
It's an array of objects of number/prefix pairs.
[ { "number": 1e+3, "suffix": "K" }, { "number": 1e+6, "suffix": "M" }, { "number": 1e+9, "suffix": "G" }, { "number": 1e+12, "suffix": "T" }, { "number": 1e+15, "suffix": "P" }, { "number": 1e+18, "suffix": "E" }, { "number": 1e+21, "suffix": "Z" }, { "number": 1e+24, "suffix": "Y" } ]If the number is bigger than the
numberir will be converted to the appropriate bigger number with prefix.E.g. as per above
1500will be converted to1.5K.Please note that for this transformation to be enabled, you need to enable it specific modifier in your format setting.
The modifier for big/small number modification is "a":
{myfield.formatNumber("#,###.00a")}More info: Formatting Numbers Tutorial on number formatting
bytePrefixesType
INumberSuffix[]Basically the same as
bigNumberPrefixes, except base for calculation is not thousand but byte (1024).The modifier is "b".
{myfield.formatNumber("#,###.00b")}The above
2048will change to2K.More info: Formatting Numbers Tutorial on number formatting
forceLTRType
booleanintlLocalesType
stringLocales if you are using date formats in
Intl.NumberFormatOptionssyntax.More info: (@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/NumberFormat) about using Intl for number formatting
languageType
LanguageA reference to
Languageinstance.Formatter will use language to translate various items, like number suffixes, etc.
negativeBaseType
numberDefault0Negative base for negative numbers.
More info: Formatting Numbers Tutorial on number formatting
numberFormatType
string|NumberFormatOptionsDefault"#,###.#####"Number format.
More info: Formatting Numbers Tutorial on number formatting
smallNumberPrefixesType
INumberSuffix[]Prefixes for big numbers.
It's an array of objects of number/prefix pairs.
[ { "number": 1e-24, "suffix": "y" }, { "number": 1e-21, "suffix": "z" }, { "number": 1e-18, "suffix": "a" }, { "number": 1e-15, "suffix": "f" }, { "number": 1e-12, "suffix": "p" }, { "number": 1e-9, "suffix": "n" }, { "number": 1e-6, "suffix": "μ" }, { "number": 1e-3, "suffix": "m" } ]If the number is smaller than the
numberir will be converted to the appropriate smaller number with prefix.E.g. as per above
0.0015will be converted to1.5m.Please note that for this transformation to be enabled, you need to enable it specific modifier in your format setting.
The modifier for big/small number modification is "a":
{myfield.formatNumber("#,###.00a")}IMPORTANT: The order of the suffixes is important. The list must start from the smallest number and work towards bigger ones.
More info: Formatting Numbers Tutorial on number formatting
smallNumberThresholdType
numberSince 4.6.8Any number smaller than this will be considered "small" number, which will trigger special formatting if "a" format modifier is used.
spriteType
$type.Optional<Sprite>Holds reference to parent
Spriteobject.
4 inherited items
clonedFromType
$type.Optional<this>Inherited fromBaseObjectReference to the original object this object was cloned from. We need to keep this so we can disassociate it from source object when this object is disposed.
configType
objectInherited fromBaseObjectUse this property to set JSON-based config. When set, triggers processing routine, which will go through all properties, and try to apply values, create instances, etc.
Use this with caution, as it is a time-consuming process. It's used for initialchart setup only, not routine operations.
idType
$type.Optional<string>Inherited fromBaseObjectSets the user-defined id of the element.
uidType
stringInherited fromBaseObjectReturns object's internal unique ID.
Methods
constructor()Returns
NumberFormatterConstructor
dispose()Returns
voidformat(value:number|string,
format?:string|NumberFormatOptions,
precision?:number)Returns
stringFormats the number according to specific format.
4 inherited items
clone(cloneId?:string)Returns
thisInherited fromBaseObjectMakes a copy of this object and returns the clone. Try to avoid cloning complex objects like chart, create new instances if you need them.
copyFrom(object:this)Returns
voidInherited fromBaseObjectCopies all properties and related data from different element.
getCurrentThemes()Returns
ITheme[]Inherited fromBaseObjectReturns a list of themes that should be applied to this element. It could either be a list of themes set explicitly on this element, or system-wide.
isDisposed()Returns
booleanInherited fromBaseObjectReturns if this object has been already been disposed.
Events
NumberFormatter does not have any events.