COGNOiSe.com - The IBM Cognos Community

IBM Cognos 10 Platform => Cognos 10 BI => Report Studio => Topic started by: CognosBen on 25 Nov 2016 06:40:37 AM

Title: Problems with decimals and percentage
Post by: CognosBen on 25 Nov 2016 06:40:37 AM
I'm trying to convert the value 0,906 to 0,91

Changing the data type and setting max two decimals will not help me since I'm going to do a calculation based on the two data fields.
When I'm doing a calculation to see the difference in percentage in the example below, I will get 1% difference, and that looks very strange since both values are on 91% with 2 decimals.

Value 1: 0,906 | 91%
Value 2: 0,913 | 91%
Value 2 - Value 1 = 0,007 | 1%

I have tried to use Cast((0.906) as numeric(5,2)) and Cast((0.906) as numeric(5,2))
In SQL, this will return 0.91, but in Cognos this returns 0.9

Does anyone know why? And know how I can fix this?
Title: Re: Problems with decimals and percentage
Post by: HalfBloodPrince on 25 Nov 2016 06:50:21 AM
Try abs(0.906) and check  if you get the desired result.
Title: Re: Problems with decimals and percentage
Post by: CognosBen on 25 Nov 2016 07:03:37 AM
Hi,

ABS(0.906) returns 0.906
Title: Re: Problems with decimals and percentage
Post by: hespora on 25 Nov 2016 07:55:50 AM
Am I missing the obvious?

_round([value],2)

should do exactly what you want as a cognos function, or round([value],2) for pretty much any vendor's db function. Casting is for datatype conversions and should not change your value.
Title: Re: Problems with decimals and percentage
Post by: CognosBen on 25 Nov 2016 08:12:55 AM
Quote from: hespora on 25 Nov 2016 07:55:50 AM
Am I missing the obvious?

_round([value],2)

should do exactly what you want as a cognos function, or round([value],2) for pretty much any vendor's db function. Casting is for datatype conversions and should not change your value.


Thanks!! You are my hero! :)
Title: Re: Problems with decimals and percentage
Post by: hespora on 25 Nov 2016 08:15:18 AM
You're welcome; glad I could help! :)