Skip to main content Skip to complementary content
Close announcements banner

Setting precision for BigDecimal numbers through schema

About this task

You can have numbers that are of BigDecimal type being displayed at a given precision (that is, the number of digits to the right of the decimal point) by setting the precision for the corresponding columns in the schema. With the precision set for a schema column that is of BigDecimal type, numbers in the column will be rounded in the HALF_UP mode.

The following Job displays the same number at different precisions. Take the following steps to set up and run the Job.

Job in the design workspace.

Procedure

  1. Launch Talend Studio and create an empty standard Job.
  2. Drag and drop tFixedFlowInput and tLogrow to the work space from Palette.
  3. Connect the two components using a Row > Main connection.
  4. Double-click the tFixedFlowInput component to open its Basic settings view and do the following.
    1. Open the schema editor by clicking the [...] button next to Edit schema and add four columns, which are of the BigDecimal type and have different precision settings.
      Schema editor.
    2. Select the Use Single Table option and enter the same value (new BigDecimal("123456.9876") in this example) for the four columns.
      Basic settings view of the component.
    3. Leave the other options as they are.
  5. Double-click the tLogRow component to open its Basic settings view and do the following.
    1. Click the Sync columns button to synchronise the schema of the component with that of the tFixedFlowInput component.
    2. Select Table (print values in cells of a table) option.
    3. Leave the other options as they are.
  6. Press F6 to run the Job.

    The following execution result shows that the numbers are rounded according to the precision settings in the schema.

    Execution results.

Did this page help you?

If you find any issues with this page or its content – a typo, a missing step, or a technical error – let us know how we can improve!