DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Newsletter
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • DZone Community Awards 2022
  • Anthropic’s Model Context Protocol (MCP): A Developer’s Guide to Long-Context LLM Integration
  • Java and MongoDB Integration: A CRUD Tutorial [Video Tutorial]
  • Unraveling Lombok's Code Design Pitfalls: Exploring Encapsulation Issues

Trending

  • AI Coding Agent Guardrails: Finding Gaps in Tool Permissions
  • When One Docker Swarm Replica Became Unreachable Over an Overlay Network: A Production Case With Traefik
  • Event-Driven AI Systems With Kafka and Autonomous Agents
  • Claude Code Superpowers: The 5-Tool Stack That Ends Limits and Context Amnesia

Draft This article hasn't been published, so readers can't see it.

In moderation This article is waiting for review, so readers can't see it yet.

Deleted This article has been deleted, so readers can't see it.

  1. DZone
  2. Culture and Methodologies
  3. Career Development
  4. Handling BigDecimal in Talend

Handling BigDecimal in Talend

If you are dealing with money or precision is a must, use BigDecimal. Otherwise, Doubles tend to be good enough. Let's dive into this concept a little more.

By 
Madhuka Udantha
·
Jan. 29, 18 · Tutorial
Post on X (opens in a new tab) Share on LinkedIn (opens in a new tab)
16.2K Views

Join the DZone community Save articles, join the discussion, and download Refcards and Trend Reports with a free account.

Join for free Already a member? Log in

This post is very basic one since Talend is all about data integration. Finding a BigDecimal in such a dataset is very common.

BigDecimal vs. Doubles

A BigDecimal is an exact way of representing numbers. A Double has a certain precision. Working with Doubles of various magnitudes (say, d1=1000.0 and d2=0.001) could result in the 0.001 being dropped altogether when summing, as the difference in magnitude is so large. With BigDecimal, this would not happen.

The disadvantage of BigDecimal is that it's slower, and it's a bit more difficult to program algorithms that way (due to +, -, *, and / not being overloaded).

If you are dealing with money or precision is a must, use BigDecimal. Otherwise, Doubles tend to be good enough.

BigDecimal Example

First, we go with a BigDecimal value such as 1.8772265500517E19. It means 1.8772265500517 x 1019 . We need to pass it without scientific notation. You can use a tJava comment in Talend and use simple Java to achieve this.

BigDecimal bigDecimal = new BigDecimal("1.8772265500517E19");
System.out.println(bigDecimal.toPlainString());

If you think you need to specify decimal point count, you can use the below line:

System.out.printf("%1$.2f", bigDecimal);

2 is the number of decimal places you want. You can change this as you need to.

image

Here is the output:

image

Doubles Example

There are a few ways to achieve this such as Talend Routines, tJava, etc. But here, we used the tJava component. Add the below lines to the Basic setting panel tab:

double sampleDouble =  1.8772265500528E9;
System.out.println(sampleDouble);
NumberFormat formatter = new DecimalFormat("###.####");
String sampleDoubleString = formatter.format(sampleDouble);  
System.out.println(sampleDoubleString);

Then, add the below imports to the Advanced settings tab:

import java.text.NumberFormat;
import java.text.DecimalFormat;

image

Here is the output of the job:

image

Make sure you used BigDecimal and Doubles in a correct way in the correct places.

Precision (computer science) IT Magnitude (astronomy) career Data (computing) Pass (software) Java (programming language) POST (HTTP) Integration

Published at DZone with permission of Madhuka Udantha. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • DZone Community Awards 2022
  • Anthropic’s Model Context Protocol (MCP): A Developer’s Guide to Long-Context LLM Integration
  • Java and MongoDB Integration: A CRUD Tutorial [Video Tutorial]
  • Unraveling Lombok's Code Design Pitfalls: Exploring Encapsulation Issues

Partner Resources

×

Comments

Loading comments

The comments didn't load

Please try again in a moment.

Likes

Loading

The next likes didn't load. Please try again.

The likes didn't load

Please try again in a moment.

See who liked this

Log in or join DZone for free to see who liked this article.

Log in Join for free
  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook