[resolved] Convert Double to Integer

One Star

[resolved] Convert Double to Integer

I am the using following code to calculate an integer representing "months of valuation" for my data. I need to figure out how to round off my result to the nearest integer.

TalendDate.diffDate((TalendDate.getLastDayOfMonth(TalendDate.addDate(TalendDate.getCurrentDate(),-1,"MM"))),(TalendDate.isDate(row1.Policy_Effective_Date___Formatted,"MM/dd/yyyy") ? TalendDate.parseDate("MM/dd/yyyy", row1.Policy_Effective_Date___Formatted) : null))
Five Stars

Re: [resolved] Convert Double to Integer

You should just have to type (int) Math.round( before the rest of your code, like this:
(int) Math.round(TalendDate.diffDate((TalendDate.getLastDayOfMonth(TalendDate.addDate(TalendDate.getCurrentDate(),-1,"MM"))),(TalendDate.isDate(row1.Policy_Effective_Date___Formatted,"MM/dd/yyyy") ? TalendDate.parseDate("MM/dd/yyyy", row1.Policy_Effective_Date___Formatted) : null)))
One Star

Re: [resolved] Convert Double to Integer

Adding (Int) did not resolve the issue - please see image. I tried to set the precision to 0, but for some reason it won't allow me to do so. I've also tried this with data type double in case null values are creating problems, but come up with the same errors.
Five Stars

Re: [resolved] Convert Double to Integer

ejgallagher wrote:
Adding (Int) did not resolve the issue - please see image. I tried to set the precision to 0, but for some reason it won't allow me to do so. I've also tried this with data type double in case null values are creating problems, but come up with the same errors.

Apparently I edited my post after you quoted me but before you finished creating your reply so bad timing on my part. Take a look at it again, if you include the (int) Math.round( yourcode ) it works. I just tried it out myself.

Sorry that it took so long, you must have been really frustrated because everything you tried should have worked (reducing the precision, casting it to an int without the rounding, etc).
One Star

Re: [resolved] Convert Double to Integer

Thanks so much for the assistance.

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

Definitive Guide to Data Quality

Create systems and workflow to manage clean data ingestion and data transformation.

Download

Tutorial

Introduction to Talend Open Studio for Data Integration.

Watch

Downloads and Trials

Test drive Talend's enterprise products.

Downloads