Work with decimal data

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

  1. Go to the Wrangler workspace in Cloud Data Fusion.
  2. 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 aBigDecimal type. Whenyou create the pipeline from Wrangler, the column is then converted tothedecimal data type.
    • If your dataset contains non-decimal data that you want to convert todecimals, use theset-column directive:

      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 calledcost from 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)}

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.

TransformationDirective
Get the absolute valueset-column :OUTPUT_COLUMNDECIMAL_COLUMN.abs()
Get the precision of a decimal valueset-column :OUTPUT_COLUMNDECIMAL_COLUMN.precision()
Get the scale of a decimal valueset-column :OUTPUT_COLUMNDECIMAL_COLUMN.scale()
Get the unscaled value of a decimal valueset-column :OUTPUT_COLUMNDECIMAL_COLUMN.unscaledValue()
Add two decimal columnsset-column :OUTPUT_COLUMNDECIMAL_COLUMN.add(DECIMAL_COLUMN_2)
Subtract a decimal from anotherset-column :OUTPUT_COLUMNDECIMAL_COLUMN.subtract(DECIMAL_COLUMN_2)
Multiply a decimal with anotherset-column :OUTPUT_COLUMNDECIMAL_COLUMN.multiply(DECIMAL_COLUMN_2)
Divide a decimal column by another and return the quotientset-column :OUTPUT_COLUMNDECIMAL_COLUMN.divide(DECIMAL_COLUMN_2)
Divide a decimal column by another and return the remainderset-column :OUTPUT_COLUMNDECIMAL_COLUMN.remainder(DECIMAL_COLUMN_2)
Convert decimal to a integerset-column :OUTPUT_COLUMNDECIMAL_COLUMN.intValue()
Convert decimal to a longset-column :OUTPUT_COLUMNDECIMAL_COLUMN.longValue()
Convert decimal to a floatset-column :OUTPUT_COLUMNDECIMAL_COLUMN.floatValue()
Convert decimal to a doubleset-column :OUTPUT_COLUMNDECIMAL_COLUMN.doubleValue()
Check if a decimal value is equal to anotherset-column :OUTPUT_COLUMNDECIMAL_COLUMN.equals(DECIMAL_COLUMN_2)
Find the maximum of two decimal columnsset-column :OUTPUT_COLUMNDECIMAL_COLUMN.max(DECIMAL_COLUMN_2)
Find the minimum of two decimal columnsset-column :OUTPUT_COLUMNDECIMAL_COLUMN.min(DECIMAL_COLUMN_2)
Move the decimal point n places to the leftset-column :OUTPUT_COLUMNDECIMAL_COLUMN.movePointLeft(n)
Move the decimal point n places to the rightset-column :OUTPUT_COLUMNDECIMAL_COLUMN.movePointRight(n)
Get the nth power of a decimalset-column :OUTPUT_COLUMNDECIMAL_COLUMN.pow(n)
Negate a decimalset-column :OUTPUT_COLUMNDECIMAL_COLUMN.negate()
Strip trailing zeros in a decimalset-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

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.