Skip to main content
Announcements
Introducing Qlik Answers: A plug-and-play, Generative AI powered RAG solution. READ ALL ABOUT IT!
cancel
Showing results for 
Search instead for 
Did you mean: 
APP
Contributor
Contributor

Decimals in data type double

Hellow,

I have the following problem loading data with Talend. In my source table (PostgreSQL) i have data (double) such as

532,56

136,44

When I run the process, the data (also double) is displayed to several decimal places in the target table like this:

532,55999756

136,44000244

I need to load only the two decimal digits, as in the source table.

I tried to solve the problem by changing the precision and using functions like FIX, FFIX, REAL, convertImpliedDecimalFormat, round.... I have also tried with the different data types (float, double, bigdecimal) but the problem is not solved.

Can you advice please?

Thank you in advance.

APP

Labels (2)
1 Reply
gjeremy1617088143

Hi you can use Bigdecimal and the method setScale:

 

public BigDecimal setScale(int newScale)

Returns a

BigDecimal

 

whose scale is the specified value, and whose value is numerically equal to this

BigDecimal

 

's. Throws an

ArithmeticException

 

if this is not possible.

This call is typically used to increase the scale, in which case it is guaranteed that there exists a

BigDecimal

 

of the specified scale and the correct value. The call can also be used to reduce the scale if the caller knows that the

BigDecimal

has sufficiently many zeros at the end of its fractional part (i.e., factors of ten in its integer value) to allow for the rescaling without changing its value.

This method returns the same result as the two-argument versions of

setScale

, but saves the caller the trouble of specifying a rounding mode in cases where it is irrelevant.

Note that since

BigDecimal

 

objects are immutable, calls of this method do not result in the original object being modified, contrary to the usual convention of having methods named setX mutate field X

. Instead,

setScale

returns an object with the proper scale; the returned object may or may not be newly allocated.

Parameters:

newScale

 

- scale of the

BigDecimal

value to be returned.

Returns:

a

BigDecimal

 

whose scale is the specified value, and whose unscaled value is determined by multiplying or dividing this

BigDecimal

's unscaled value by the appropriate power of ten to maintain its overall value.

Throws:

ArithmeticException

- if the specified scaling operation would require rounding.

See Also:

setScale(int, int)

, setScale(int, RoundingMode)

 

I get it from the oracle documentation.

Send me Love and Kudos