Rounding Decimal values

Post questions here relative to DataStage Server Edition for such areas as Server job design, DS Basic, Routines, Job Sequences, etc.

Moderators: chulett, rschirm, roy

Post Reply
DS4DRIVER
Premium Member
Premium Member
Posts: 39
Joined: Thu Oct 30, 2003 1:37 pm

Rounding Decimal values

Post by DS4DRIVER »

I use a Routine to Round Decimal values. The code is as follows

Value and Digits are the paameters passed to the routine

Code: Select all

If Digits > 0 then
 Ans = FIX(Value, Digits)
End Else
 Ans = FIX(Value/100,50)*100
End
I also tried

Code: Select all

PRECISION 14
If Digits > 0 then
 Ans = FIX(Value, Digits)
End Else
 Ans = FIX(Value/100,50)*100
End
When i try the following example it does not work like how i want it
Example 1:
Value = 123456789.789947874545
Digit = 10
Result = 123456789.789948
The routine rounds of at the 6th position.
I was expecting result to be 123456789.7899478745 (round at the 10th position)

Example 2:
Value = 123456.789947874545
Digit = 10
Result = 123456.789947875
The routine rounds of at the 9th position.
I was expecting result to be 123456.7899478745 (round at the 10th position)

Example 3:
Value = 12345.789947874545
Digit = 10
Result = 12345.7899478745
The routine rounds of at the 10th position.
The result is as expected 123456789.7899478745 (round at the 10th position)

Looks like it it something to do with the Integer part of the Decimal value, when the value was increased from 12345.789947874545 to 123456.7899478745, there was a difference in rounding.

Is there any other optional way to make the Round work the way i want.
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Fmt(expression, "20R9") will give you nine digits after the decimal place. You may wish to apply a TrimF() function to that result.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
girish119d
Participant
Posts: 5
Joined: Thu Jul 27, 2006 2:37 pm

Re: Rounding Decimal values

Post by girish119d »

Fmt(expression, "R10")

Try above thig as well
DS4DRIVER wrote:I use a Routine to Round Decimal values. The code is as follows

Value and Digits are the paameters passed to the routine

Code: Select all

If Digits > 0 then
 Ans = FIX(Value, Digits)
End Else
 Ans = FIX(Value/100,50)*100
End
I also tried

Code: Select all

PRECISION 14
If Digits > 0 then
 Ans = FIX(Value, Digits)
End Else
 Ans = FIX(Value/100,50)*100
End
When i try the following example it does not work like how i want it
Example 1:
Value = 123456789.789947874545
Digit = 10
Result = 123456789.789948
The routine rounds of at the 6th position.
I was expecting result to be 123456789.7899478745 (round at the 10th position)

Example 2:
Value = 123456.789947874545
Digit = 10
Result = 123456.789947875
The routine rounds of at the 9th position.
I was expecting result to be 123456.7899478745 (round at the 10th position)

Example 3:
Value = 12345.789947874545
Digit = 10
Result = 12345.7899478745
The routine rounds of at the 10th position.
The result is as expected 123456789.7899478745 (round at the 10th position)

Looks like it it something to do with the Integer part of the Decimal value, when the value was increased from 12345.789947874545 to 123456.7899478745, there was a difference in rounding.

Is there any other optional way to make the Round work the way i want.
GD
Post Reply