ABS() function
Moderators: chulett, rschirm, roy
-
- Participant
- Posts: 5
- Joined: Wed Apr 20, 2005 6:29 pm
- Location: USA
ABS() function
Hi,
I have a strange experience working with the abs() function.
We have a reqirement that should take the absolute value of an integer and then rounded to two decimals. When ever we are geting some -ve numbers these are converted to +ve numbers using the abs() function, but it is loosing the precision. like for example
abs(31.33) gives 31.33 as output.
abs(-31.333) is giving 31 as output. Then we took a work around to accomplish this, by multiplying numbers less than zero with -1 and then rounding. Does any one know why is it so ?
Thanks.
I have a strange experience working with the abs() function.
We have a reqirement that should take the absolute value of an integer and then rounded to two decimals. When ever we are geting some -ve numbers these are converted to +ve numbers using the abs() function, but it is loosing the precision. like for example
abs(31.33) gives 31.33 as output.
abs(-31.333) is giving 31 as output. Then we took a work around to accomplish this, by multiplying numbers less than zero with -1 and then rounding. Does any one know why is it so ?
Thanks.
Thanks,
Kiran Kumar Reddy
Kiran Kumar Reddy
-
- Participant
- Posts: 34
- Joined: Thu Jul 29, 2004 1:03 pm
Hi Kiran,
The DataStage documentation specifies that the input argument to the abs function should be of type int32 and return type is a dfloat . But in that case even your +ve number have to be truncated. I tried it with an example and have noticed that the decimal part of my positive numbers are truncated. Are you sure that in your case for +ve numbers the fraction part was not truncated?
Thanks
The DataStage documentation specifies that the input argument to the abs function should be of type int32 and return type is a dfloat . But in that case even your +ve number have to be truncated. I tried it with an example and have noticed that the decimal part of my positive numbers are truncated. Are you sure that in your case for +ve numbers the fraction part was not truncated?
Thanks
-
- Participant
- Posts: 5
- Joined: Wed Apr 20, 2005 6:29 pm
- Location: USA
In fact I didn't find any such environment variables in our project. May be something we need to set it up now ! Thanks for your response.
Also we were getting all -ve numbers from source, so I guess we didn't actually take a +ve number and check, but somehow we got into this mis-conception, Thanks for bringing this up.
Also we were getting all -ve numbers from source, so I guess we didn't actually take a +ve number and check, but somehow we got into this mis-conception, Thanks for bringing this up.
Thanks,
Kiran Kumar Reddy
Kiran Kumar Reddy
-
- Participant
- Posts: 54607
- Joined: Wed Oct 23, 2002 10:52 pm
- Location: Sydney, Australia
- Contact:
-
- Participant
- Posts: 34
- Joined: Thu Jul 29, 2004 1:03 pm
-
- Participant
- Posts: 34
- Joined: Thu Jul 29, 2004 1:03 pm