Formatting numbers in Dataseed

The general form of a specifier is:

[​[fill]align][sign][symbol][0][width][,][.precision][type]

The fill can be any character other than "{" or "}". The presence of a fill character is signaled by the character following it, which must be one of the align options.

The align can be:

  • ("<") Forces the field to be left-aligned within the available space.
  • (">") Forces the field to be right-aligned within the available space. (This is the default).
  • ("^") Forces the field to be centered within the available space.

The sign can be:

  • plus ("+") - a sign should be used for both positive and negative numbers.
  • minus ("-") - a sign should be used only for negative numbers. (This is the default.)
  • space (" ") - a leading space should be used on positive numbers, and a minus sign on negative numbers.

The symbol can be:

  • currency ("$") - a currency symbol should be prefixed (or suffixed) per the locale.
  • base ("#") - for binary, octal, or hexadecimal output, prefix by "0b", "0o", or "0x", respectively.

The "0" option enables zero-padding.

The width defines the minimum field width. If not specified, then the width will be determined by the content.

The comma (",") option enables the use of a comma for a thousands separator.

The precision indicates how many digits should be displayed after the decimal point for a value formatted with types "f" and "%", or before and after the decimal point for a value formatted with types "g", "r" and "p".

The available type values are:

  • exponent ("e") - use Number.toExponential.
  • general ("g") - use Number.toPrecision.
  • fixed ("f") - use Number.toFixed.
  • integer ("d") - use Number.toString, but ignore any non-integer values.
  • rounded ("r") - round to precision significant digits, padding with zeroes where necessary in similar fashion to fixed ("f"). If no precision is specified, falls back to general notation.
  • percentage ("%") - like fixed, but multiply by 100 and suffix with "%".
  • rounded percentage ("p") - like rounded, but multiply by 100 and suffix with "%".
  • binary ("b") - outputs the number in base 2.
  • octal ("o") - outputs the number in base 8.
  • hexadecimal ("x") - outputs the number in base 16, using lower-case letters for the digits above 9.
  • hexadecimal ("X") - outputs the number in base 16, using upper-case letters for the digits above 9.
  • character ("c") - converts the integer to the corresponding unicode character before printing.
  • SI-prefix ("s") - like rounded, but with a unit suffixed such as "9.5M" for mega, or "1.00µ" for micro.

The type "n" is also supported as shorthand for ",g".

Have more questions? Submit a request

0 Comments

Please sign in to leave a comment.
Powered by Zendesk