How to remove decimal points from string field and round off

Highlighted
Six Stars

How to remove decimal points from string field and round off

Hello Folks,

 

I am new to Talend. I need below help.

 

I have input .like this which is String type in .csv file. 

3040000000005.78

 

And I want to convert this to 3040000000006

 

This has removing decimal and round off to nearest integer.

 

Regards,

Deepak

Tags (1)
Community Manager

Re: How to remove decimal points from string field and round off

There is a quite a straight forward answer to this using the BigDecimal class. Try this in a tJava component....

 

String stringNum = "3040000000005.78";
BigDecimal bd = new BigDecimal(stringNum);

System.out.println(bd.setScale(0, BigDecimal.ROUND_HALF_UP).toPlainString());

2019 GARNER MAGIC QUADRANT FOR DATA INTEGRATION TOOL

Talend named a Leader.

Get your copy

OPEN STUDIO FOR DATA INTEGRATION

Kickstart your first data integration and ETL projects.

Download now

What’s New for Talend Summer ’19

Watch the recorded webinar!

Watch Now

Self-service Talend Migration: Moving from On-Premises to the Cloud

Move from On-Premises to the Cloud by following the advice of experts

Read Now

Modern Data Engineering in the Cloud

Learn about modern data engineering in the Cloud

Watch Now

How to deploy Talend Jobs as Docker images to Amazon, Azure and Google Cloud reg...

Learn how to deploy Talend Jobs as Docker images to Amazon, Azure and Google Cloud registries

Blog