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 r088

D toc

Excerpt

Converts a string formatted as a number into an Integer or Decimal value by parsing out the specified decimal and group separators. A string or a function returning formatted numbers of String type or a column containing formatted numbers of string type can be inputs.

You can use this function to convert String values that have locale-specific formatting to locale-independent values of Integer or Decimal type by removing the formatting separators.

  • If the source value does not include a valid input for this function, a missing value is returned.
  • This function supports negative input values.
  • Supports input for multiple locale types and returns the output of the appropriate numeric type.

For more information on number formatting string options, see Supported Numeric Formatting.

You can use decimal separators and grouping separators when working with other currency formats. More information is below.

Info

NOTE: If the decimal separator and group separator arguments are not specified, then a null value is returned.

D s lang vs sql

D s
snippetBasic

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

Numvalue(Discount, "," ,".")

Output: Returns the values from the Discount column by converting the formatted number to a numeric value using decimal and group separators.  For example, if the Discount column has values in percentage,  then it is converted into the corresponding numeric value. Example: 10% to 0.10.

Info

NOTE: If multiple percent signs are used in a column, then this function returns the decimal values accordingly. For example, an input of 9%% returns 0.0009.

Info

NOTE: This function removes any currency indicators. For example, £ 100 as an input value returns 100.


D s
snippetSyntax

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

Numvalue(formattedNumber, ["grouping_separator"], ["decimal_separator"])


ArgumentRequired?Data TypeDescription
formattedNumberYstringA string, a column of strings, or a function returning a string
grouping_separatorYstring A grouping representing grouping separator. By default, comma (,) is used as the grouping separator.
decimal_separatorYstringA string used to separate the integer and fractional part of the result. If not specified, then a null value is returned.

D s lang notes

formatted_number

Literal string value, a function that returns a string value, or the name of a column containing string values to be converted into a numeric value.

  • Multiple columns and wildcards are not supported.

D s
snippetusage

Required?Data TypeExample Value
Yesstring, a column of strings, or a function returning a formatted number string or column of stringsDiscount

grouping_separator

The string used to group a set of digits in the input values. Separators must be enclosed with double quotes (") or single quotes (').  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: When you provide invalid separators or wrong separators, you may get an error in the Formula column.

D s
snippetusage

Required?Data TypeExample Value
YesString literal','

decimal_separator

The string used to indicate the decimal point in the input values. Separators must be enclosed with double quotes ( " ) or single quotes ( ' ).

decimal separator is used to separate  the fractional  part of a number written in decimal form. 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
YesString literal'.'


Grouping SeparatorDecimal SeparatorExample Locale
Comma (,)Period (.)U.S locale
Period (.)Comma (,)Spanish locale
SpaceComma (,)French locale

D s
snippetExamples

Example - formatting price and percentages

This example shows how to convert the formatted number of string type into a numeric value. The following table shows different types of products and their total sales in the UK region. From this example, you must convert the total sales value for the U.S region.

First, you must convert the global currency formats into a generic numeric value, then proceed with the conversion calculation.

Source:

ProductsTotal_Sales_UK

Baby Foods

£ 100.00

Medicines

£  150.00

Groceries

£  200.00

Kitchen Supplies

£  25.00

Cosmetics

£  250.00

Snacks

£  50.00

Transformation:

The first transformation is to convert the Total_Sales_UK column into a numeric value. In this case, when a Numvalue function is applied, the value with the currency symbols returns only the numeric value. You can see the currency symbol is removed when using the Numvalue function.

D trans
RawWrangletrue
Typestep
WrangleTextderive type:single value: NUMVALUE (Total_Sales_UK, ",",".")
p01Namecolumns
p01ValueTotal_Sales_UK
p02NameFormula
p02ValueNUMVALUE (Total_Sales_UK, ",",".")
p03NameNew column name
SearchTermEdit column with formula

The second step consists of converting the U.K Pounds (£) to U.S Dollars ($) for better computations. In this step, you multiply the Total_Sales_UK column with the ratio conversion rate. Let's say the current conversion rate is 1.36, then multiply the U.K Pounds with 1.36 to convert to U.S Dollars. As a part of this transformation, the Total_Sales_US column is created.

D trans
RawWrangletrue
p03ValueTotal_Sales_US
Typestep
WrangleTextderive type:single value: NUMVALUE
p01NameFormula type
p01ValueSingle row formula
p02NameFormula
p02ValueTotal_Sales_UK * 1.36
p03NameNew column name
SearchTermNew formula

After you get the U.S conversion, you can format the values using the Numformat function. The Numformat function formats a numeric set of values according to the specified number formatting.

D trans
RawWrangletrue
Typestep
WrangleTextderive type:single value: NUMVALUE
p01Namecolumns
p01ValueTotal_Sales_US
p02NameFormula
p02ValueNUMFORMAT(Total_Sales_US, '$###,###.00', ',', '.')
SearchTermEdit column with formula

Results

The output data should look like the following:

ProductsTotal_Sales_UKTotal_Sales_US

Baby Foods

£   100.00

$136.00

Medicines

£   150.00 $204.00

Groceries

£   200 .00 $272.00

Kitchen Supplies

£   25 .00 $34. 00

Cosmetics

£   250 .00 $340. 00

Snacks

£   50 .00 $68. 00


Noprint

See Also

Content by Label
showLabelsfalse
showSpacefalse
cqllabel = "math" and space = currentSpace()