Page tree

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Published by Scroll Versions from space DEV and version r095

...

Excerpt

Formats a numeric set of values according to the specified number formatting. Source values can be a literal numeric value, a function returning a numeric value, or reference to a column containing an Integer or Decimal values.

  • If the source value does not include a valid input for this function, a missing value is returned.
  • When a NUMFORMAT transform this function is applied, the column can be re-typed to a different data type. For example, if your format string (second parameter) is '#' (a single hash mark), then all values are rounded to the nearest integer, and the column is re-typed as Integer. 

    Tip

    Tip: In general, you should format your numeric data after you have completed your computations on it. In some cases, you might lose numeric precision in converting formats, or your data can be re-typed to a different data type (e.g. For example, Decimal to Integer).

    For more information on formatting date values, see DATEFORMAT Function

    .

  • You can also use decimal separators and grouping separators when working with data from multiple locales. If no separators are provided, the U.S. format separators are used.

  • When this function is applied to any column, the resulting column is of String type, so arithmetic operations are not possible on the resulting column.
Info

NOTE: If the function is unable to process the value, a null value is returned on

D s photon
. On other running environments, trailing characters that do not apply to numeric values or their formatting are simply dropped.

D s product
rtrue
supports a wide variety of number formats, following Java standards. For more information, please see Java's documentation.

Info

NOTE: This function just changes how the underlying cell value is displayed. If you round the value to a specific level of precision, please use the ROUND function. See ROUND Function.

For more information on formatting date values, see DATEFORMAT Function.

D s lang vs sql

D s
snippetBasic

numformat
D lang syntax
RawWrangletrue
Typeref
showNotetrue
WrangleTextderive type:single value: numformat(MyPrice, '$###,###.##') as: 'dateformat_MyPrice'
, grouping separator, decimal separator))

Numformat(MyPrice, '$###,###.##$ ##,##.#', ',' ,'.')

Output: Returns the values from the MyPrice column converted to a price formatby formatting the values using the specified formatting string and group and separators separators. For example, if the MyPrice column has a value of 12345.12 then it can be reformatted to $ 1,23,45.12 by using the above parameters.

D s
snippetSyntax

D lang syntax
RawWrangletrue
Typesyntax
showNotetrue
WrangleTextderive type:single value:numformat(numeric_col, number_format_string)

numformatNumformat(numeric_val, number_format_string, [grouping_separator], [decimal_separator])


ArgumentRequired?Data TypeDescription
numeric_valYstring, integer, or decimalLiteral value, function returning a numeric value, or name of Integer or Decimal column whose values are to be formatted
number_format_stringYstringLiteral value of the number formatting string to apply used to indicate location of separators, number of required digits, currency, percentage, and sign.
grouping_separatorNstringA grouping representing grouping separator. By default, comma (,) is used as the grouping separator.
decimal_separatorN
stringA string representing decimal separator. By default, period (.) is used as the decimal separator.

D s lang notes

numeric_val

...

  • Values with more than 20 digits after the decimal point Decimal point are truncated by this function.

  • Missing values for this function in the source data result in missing values in the output.
  • Multiple columns and wildcards are not supported.
  • Using a dash as a negative value indicator (e.g. '-###.00') in your formatting string can change values and their data types. 

D s
snippetusage

Required?Data TypeExample Value
YesString (column reference), function, or Integer or Decimal literalMyPrice

...

Info

NOTE: You cannot create number format strings in which a 0 value appears before a # value. The following example strings are not supported: #.#0, #.#0#, #.#00

 

Some key codes:

...

'###,###'

...

99

999

1000

10000

...

99

999

1,000

10,000

...

20

7.1

...

20

07.1

...

D s product
supports Java number formatting strings, with some exceptions.

Missing values for this function in the source data result in missing values in the output

D s
snippetusage

Required?Data TypeExample Value
YesString'###.00'

grouping_separator

The string used to separate a group of digits. For example, a comma (,) is used as a grouping separator in the U.S.A (“10,000”), whereas space is used in France (“10 000”).

Info

NOTE: If a space is used as the grouping separator, then any space values between a currency indicator and digits are automatically trimmed. A grouping separator should not be inserted between a currency indicator and a digit.


Info

NOTE: Using invalid separators or wrong separators may generate errors in your recipe step.

D s
snippetusage

Required?Data TypeExample Value
NoString','

decimal_separator

The string used to separate the integer part of a Decimal value from its fractional part. For example, a period(.) is used as a decimal separator in the U.S.A ("1234.12"), whereas comma (,) is used in France ("1234,12").


D s
snippetusage


Required?Data TypeExample Value
Yes
NoString'
#
.
#
'


D s
snippetExamples
D s product
supports Java number formatting strings, with some exceptions.

Example - formatting price and percentages

This example steps through how to manage number formatting for price and percentage data when you have to must perform some computations on the data in the application.

...

You can re-type the OrderId column to String without issue. If you retype the other three columns, all values are mismatched. You can use the following transforms to remove the currency and percentage notation. The first transform removes the trailing % sign from every value across all columns using a

D s item
pattern
itempattern
.

D trans
RawWrangletrue
p03Value''
Typestep
WrangleTextreplace col: * on: `\%{end}` with: ''
p01NameColumns
p01ValueAll
p02NameFind
p02Value`\%{end}`
p03NameReplace with
SearchTermReplace text or pattern

...

D trans
RawWrangletrue
Typestep
WrangleTextset col:SubTotal value:numformat(SubTotal, '#.00')
p01NameColumns
p01ValueSubTotal
p02NameFormula
p02ValuenumformatNUMFORMAT(SubTotal, '#.00', ',' ,'.')
SearchTermEdit column with formula

...

The Discount and TaxRate values should be converted to decimalsDecimals. The following adjusts the Discount column:

...

OrderIdQtyUnitPriceSubTotalDiscountDiscountedTotalTaxRateTotal
1001525.00125.000125.000.0825135.31
10021539.99599.850.05569.860.0825616.87
1003299.99199.980.15169.980.0825184.01
1004100999.9999999.00099999.000.0825108248.92

...

See Also

...

D s also
labelmath