Skip to content

NumberFieldFormat

ESM: import NumberFieldFormat from "@arcgis/core/layers/support/NumberFieldFormat.js";
CDN: const NumberFieldFormat = await $arcgis.import("@arcgis/core/layers/support/NumberFieldFormat.js");
Class: @arcgis/core/layers/support/NumberFieldFormat
Inheritance: NumberFieldFormatAccessor
Since: ArcGIS Maps SDK for JavaScript 4.34

The NumberFieldFormat class defines the formatting options for numeric field types. It is used in the FieldConfiguration class to define the display format of fields in a FeatureLayer. It is also used in the FieldInfo class to define the display format of fields content in a PopupTemplate.

It applies to both the map's popup and any components/widgets that display the field.

Breaking change Numeric fields with decimal values are now automatically formatted with a limit on decimal places. For example, a value such as 1.234566788 would display with all available decimal places in the FeatureTable. Now, if no field configurations are defined, components automatically limit the display to three decimal places (1.234). To customize this behavior, define field configurations on your layer.

Numeric Format Mappings

The following tables show equivalencies between the legacy FieldInfoFormat.places and FieldInfoFormat.digitSeparator values and NumberFieldFormat properties. The examples shown are for the en-US locale. Note that the actual display will vary based on the locale of the user.


Integer Field Types

Legacy NumberFieldFormat equivalency Example (en-US)
digitSeparator = true useGrouping = "always" 1,234,567
digitSeparator = false useGrouping = "never" 1234567

Floating-point field types

Legacy NumberFieldFormat equivalency Example: (en-US) Input NumberFieldFormat output
digitSeparator = true, places = 4 useGrouping = "always", minimumFractionDigits = 4, maximumFractionDigits = 4 1,234.5678 1,234.5678
digitSeparator = false, places = 4 useGrouping = "never", minimumFractionDigits = 4, maximumFractionDigits = 4 1234.5678 1234.5678
digitSeparator = false, places = 3 useGrouping = "never", minimumFractionDigits = 2, maximumFractionDigits = 3 1234.323443 1234.323
digitSeparator = true, places = 2 useGrouping = "auto", minimumFractionDigits = 3, maximumFractionDigits = 3 1,234.323443 1,234.323

See also
Example
// Create a number field format
const numberFieldFormat = new NumberFieldFormat ({
  minimumFractionDigits: 1,
  maximumFractionDigits: 3,
  useGrouping: "never"
});

// Create a field configuration object containing the number format
const numberFieldConfiguration = new FieldConfiguration ({
  name: "voterCount", // name of the field in the service
  fieldFormat: numberFieldFormat,
  alias: "Voter Count"
});

// Create a feature layer and pass in the field configurations
const featureLayer = new FeatureLayer ({
  url: "url to feature layer",
  outFields: ["*"],
  fieldConfigurations: [numberFieldConfiguration] // add as many field configurations as needed
});

Constructors

NumberFieldFormat

Constructor
new NumberFieldFormat(properties)
Parameter
properties Object
optional

See the properties for a list of all the properties that may be passed into the constructor.

Property Overview

Any properties can be set, retrieved or listened to. See the Watch for changes topic.
Show inherited properties Hide inherited properties
Name Type Summary Class

The name of the class.

Accessor

The maximum number of decimal places to display.

NumberFieldFormat

The minimum number of decimal places to display.

NumberFieldFormat

The formatting style to use.

NumberFieldFormat

The type of field format.

NumberFieldFormat

Indicates whether to use grouping separators, such as thousands separators.

NumberFieldFormat

Property Details

declaredClass

Inherited
Property
declaredClass Stringreadonly
Inherited from Accessor

The name of the class. The declared class name is formatted as esri.folder.className.

maximumFractionDigits

Property
maximumFractionDigits Number

The maximum number of decimal places to display. If the number has more decimal places, it will be rounded to the nearest value with the specified number of decimal places. For example, if maximumFractionDigits is set to 2, the number 3.456 will be displayed as 3.46.

minimumFractionDigits

Property
minimumFractionDigits Number

The minimum number of decimal places to display. If the number has fewer decimal places, it will be padded with trailing zeros. If the number has more decimal places, it will be rounded to the nearest value with the specified number of decimal places. For example, if minimumFractionDigits is set to 2, the number 3.1 will be displayed as 3.10 and the number 3.456 will be displayed as 3.46.

style

Property
style Stringreadonly

The formatting style to use. Support is currently limited to decimal style.

For NumberFieldFormat the style is always "decimal".

Default Value:decimal
See also

type

Property
type Stringreadonly

The type of field format.

For NumberFieldFormat the type is always "number".

useGrouping

Property
useGrouping String

Indicates whether to use grouping separators, such as thousands separators. For example, if useGrouping is set to always, the number 1234567 will be displayed as 1,234,567. If set to never, the number will be displayed as 1234567. auto is the default value and uses grouping separators based on the locale and the number of digits.

Possible Values:"always" |"auto" |"never"

Default Value:auto
See also

Method Overview

Show inherited methods Hide inherited methods
Name Return Type Summary Class

Adds one or more handles which are to be tied to the lifecycle of the object.

Accessor
this

Creates a deep clone of this object.

NumberFieldFormat

Creates a new instance of this class and initializes it with values from a JSON object generated from an ArcGIS product.

NumberFieldFormat

Returns true if a named group of handles exist.

Accessor

Removes a group of handles owned by the object.

Accessor

Converts an instance of this class to its ArcGIS portal JSON representation.

NumberFieldFormat

Method Details

addHandles

Inherited
Method
addHandles(handleOrHandles, groupKey)
Inherited from Accessor

Adds one or more handles which are to be tied to the lifecycle of the object. The handles will be removed when the object is destroyed.

// Manually manage handles
const handle = reactiveUtils.when(
  () => !view.updating,
  () => {
    wkidSelect.disabled = false;
  },
  { once: true }
);

this.addHandles(handle);

// Destroy the object
this.destroy();
Parameters
handleOrHandles WatchHandle|WatchHandle[]

Handles marked for removal once the object is destroyed.

groupKey *
optional

Key identifying the group to which the handles should be added. All the handles in the group can later be removed with Accessor.removeHandles(). If no key is provided the handles are added to a default group.

clone

Method
clone(){this}

Creates a deep clone of this object. Any properties that store values by reference will be assigned copies of the referenced values on the cloned instance.

Returns
Type Description
this A deep clone of the class instance that invoked this method.

fromJSON

Method
fromJSON(json){* |null |undefined}static

Creates a new instance of this class and initializes it with values from a JSON object generated from an ArcGIS product. The object passed into the input json parameter often comes from a response to a query operation in the REST API or a toJSON() method from another ArcGIS product. See the Using fromJSON() topic in the Guide for details and examples of when and how to use this function.

Parameter
json Object

A JSON representation of the instance in the ArcGIS format. See the ArcGIS REST API documentation for examples of the structure of various input JSON objects.

Returns
Type Description
* | null | undefined Returns a new instance of this class.

hasHandles

Inherited
Method
hasHandles(groupKey){Boolean}
Inherited from Accessor

Returns true if a named group of handles exist.

Parameter
groupKey *
optional

A group key.

Returns
Type Description
Boolean Returns true if a named group of handles exist.
Example
// Remove a named group of handles if they exist.
if (obj.hasHandles("watch-view-updates")) {
  obj.removeHandles("watch-view-updates");
}

removeHandles

Inherited
Method
removeHandles(groupKey)
Inherited from Accessor

Removes a group of handles owned by the object.

Parameter
groupKey *
optional

A group key or an array or collection of group keys to remove.

Example
obj.removeHandles(); // removes handles from default group

obj.removeHandles("handle-group");
obj.removeHandles("other-handle-group");

toJSON

Method
toJSON(){Object}

Converts an instance of this class to its ArcGIS portal JSON representation. See the Using fromJSON() guide topic for more information.

Returns
Type Description
Object The ArcGIS portal JSON representation of an instance of this class.

Your browser is no longer supported. Please upgrade your browser for the best experience. See our browser deprecation post for more details.