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
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Modernize your data layer. Learn how to design cloud-native database architectures to meet the evolving demands of AI and GenAI workkloads.

Secure your stack and shape the future! Help dev teams across the globe navigate their software supply chain security challenges.

Releasing software shouldn't be stressful or risky. Learn how to leverage progressive delivery techniques to ensure safer deployments.

Avoid machine learning mistakes and boost model performance! Discover key ML patterns, anti-patterns, data strategies, and more.

Related

  • DZone Community Awards 2022
  • Java and MongoDB Integration: A CRUD Tutorial [Video Tutorial]
  • Unraveling Lombok's Code Design Pitfalls: Exploring Encapsulation Issues
  • Enterprise RIA With Spring 3, Flex 4 and GraniteDS

Trending

  • The Role of Functional Programming in Modern Software Development
  • It’s Not About Control — It’s About Collaboration Between Architecture and Security
  • Debugging Core Dump Files on Linux - A Detailed Guide
  • SQL Server Index Optimization Strategies: Best Practices with Ola Hallengren’s Scripts
  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 user avatar
Madhuka Udantha
·
Jan. 29, 18 · Tutorial
Likes (1)
Comment
Save
Tweet
Share
15.4K Views

Join the DZone community and get the full member experience.

Join For Free

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, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • DZone Community Awards 2022
  • Java and MongoDB Integration: A CRUD Tutorial [Video Tutorial]
  • Unraveling Lombok's Code Design Pitfalls: Exploring Encapsulation Issues
  • Enterprise RIA With Spring 3, Flex 4 and GraniteDS

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

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 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!