Work with decimal data Stay organized with collections Save and categorize content based on your preferences.
This page explains how to convert fields into the decimals and performtransformations on them when you prepare data in the Wrangler workspace of theCloud Data Fusion Studio.
Read decimal data
- Go to the Wrangler workspace in Cloud Data Fusion.
Open an object, such as a table, from a database or a Cloud Storage file.
- For a database or a BigQuery connection, if the tablehas a decimal column, Wrangler converts it into a
BigDecimaltype. Whenyou create the pipeline from Wrangler, the column is then converted tothedecimaldata type. If your dataset contains non-decimal data that you want to convert todecimals, use the
set-columndirective:set-column :DECIMAL_COLUMN exp:{new("java.math.BigDecimal",INPUT_COLUMN)}Replace the following:
DECIMAL_COLUMN: the decimal column to betransformed. After the directive executes, the column's data typechanges toBigDecimal, and the schema also contains theappropriate data type.INPUT_COLUMN: the column that gets converted,which can be one of the following types:STRING,INTEGER,LONG,FLOAT, orDOUBLE.
If your dataset includes values with varying scale, such as 1.05, 2.698,5.8745512, set the scale with a Wrangler directive and edit theschema in the pipeline to set the scale for the decimal column.
To set the scale in the Wrangler, use a directive similar to thefollowing:
set-column :OUTPUT_COLUMN exp:{new("java.math.BigDecimal",DECIMAL_COLUMN).setScale()}The following example converts a column called
costfrom a string to adecimal, sets a scale of 9, and outputs the results to a new columncalledoutput-column:set-column : output-column exp:{new("java.math.BigDecimal", "cost").setScale(9)}
- For a database or a BigQuery connection, if the tablehas a decimal column, Wrangler converts it into a
Transform decimal data
Decimal columns in Wrangler use the Java BigDecimal class.After the columns are converted to the BigDecimal data type, transform thecolumns with methods fromClass BigDecimal.
| Transformation | Directive |
|---|---|
| Get the absolute value | set-column :OUTPUT_COLUMNDECIMAL_COLUMN.abs() |
| Get the precision of a decimal value | set-column :OUTPUT_COLUMNDECIMAL_COLUMN.precision() |
| Get the scale of a decimal value | set-column :OUTPUT_COLUMNDECIMAL_COLUMN.scale() |
| Get the unscaled value of a decimal value | set-column :OUTPUT_COLUMNDECIMAL_COLUMN.unscaledValue() |
| Add two decimal columns | set-column :OUTPUT_COLUMNDECIMAL_COLUMN.add(DECIMAL_COLUMN_2) |
| Subtract a decimal from another | set-column :OUTPUT_COLUMNDECIMAL_COLUMN.subtract(DECIMAL_COLUMN_2) |
| Multiply a decimal with another | set-column :OUTPUT_COLUMNDECIMAL_COLUMN.multiply(DECIMAL_COLUMN_2) |
| Divide a decimal column by another and return the quotient | set-column :OUTPUT_COLUMNDECIMAL_COLUMN.divide(DECIMAL_COLUMN_2) |
| Divide a decimal column by another and return the remainder | set-column :OUTPUT_COLUMNDECIMAL_COLUMN.remainder(DECIMAL_COLUMN_2) |
| Convert decimal to a integer | set-column :OUTPUT_COLUMNDECIMAL_COLUMN.intValue() |
| Convert decimal to a long | set-column :OUTPUT_COLUMNDECIMAL_COLUMN.longValue() |
| Convert decimal to a float | set-column :OUTPUT_COLUMNDECIMAL_COLUMN.floatValue() |
| Convert decimal to a double | set-column :OUTPUT_COLUMNDECIMAL_COLUMN.doubleValue() |
| Check if a decimal value is equal to another | set-column :OUTPUT_COLUMNDECIMAL_COLUMN.equals(DECIMAL_COLUMN_2) |
| Find the maximum of two decimal columns | set-column :OUTPUT_COLUMNDECIMAL_COLUMN.max(DECIMAL_COLUMN_2) |
| Find the minimum of two decimal columns | set-column :OUTPUT_COLUMNDECIMAL_COLUMN.min(DECIMAL_COLUMN_2) |
| Move the decimal point n places to the left | set-column :OUTPUT_COLUMNDECIMAL_COLUMN.movePointLeft(n) |
| Move the decimal point n places to the right | set-column :OUTPUT_COLUMNDECIMAL_COLUMN.movePointRight(n) |
| Get the nth power of a decimal | set-column :OUTPUT_COLUMNDECIMAL_COLUMN.pow(n) |
| Negate a decimal | set-column :OUTPUT_COLUMNDECIMAL_COLUMN.negate() |
| Strip trailing zeros in a decimal | set-column :OUTPUT_COLUMNDECIMAL_COLUMN.stripTrailingZeros() |
Replace the following:
OUTPUT_COLUMN: the column containing the output of theoperation.DECIMAL_COLUMN: the decimal column that's transformed.DECIMAL_COLUMN_2: the second decimal column included inthe operation, such as when you add the values from two decimal columnstogether.
What's next
- Learn more aboutWrangler directives.
Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-12-15 UTC.