Firstly, I think the OP's premise is incorrect. If VAR.1 = 52.6766 and he wants to round to 2 decimal places, the result would be 52.68, NOT 52.65. If VAR.1 = 52.6466, the result would be 52.65, not 52.60.

Second, X=INT(X*20+.5)/20 returns 52.7 (1 decimal place), and is a little hard to interpret. Any time I do this, I always have to think about what to multiply and divide by. I use this form:

Round to 1, then 2 decimal places (work with the OCONV version). If I goofed something up here, let me know.

Code:
VAR.1           = 52.6466
VAR.1.ROUNDED.1 = VAR.1 1
VAR.1.ROUNDED.2 = VAR.1 2
X               = INT(VAR.1 * 20 + .5) / 20
*
CRT 'VAR.1           = ': VAR.1
CRT 'VAR.1.ROUNDED.1 = ': VAR.1.ROUNDED.1
CRT 'VAR.1.ROUNDED.2 = ': VAR.1.ROUNDED.2
CRT 'X               = ': X
*
VAR.1           = 52.6766
VAR.1.ROUNDED.1 = VAR.1 1
VAR.1.ROUNDED.2 = VAR.1 2
X               = INT(VAR.1 * 20 + .5) / 20
*
CRT 'VAR.1           = ': VAR.1
CRT 'VAR.1.ROUNDED.1 = ': VAR.1.ROUNDED.1
CRT 'VAR.1.ROUNDED.2 = ': VAR.1.ROUNDED.2
CRT 'X               = ': X


Result:

VAR.1           = 52.6466
VAR.1.ROUNDED.1 = 52.6
VAR.1.ROUNDED.2 = 52.65
X               = 52.65
VAR.1           = 52.6766
VAR.1.ROUNDED.1 = 52.7
VAR.1.ROUNDED.2 = 52.68
X               = 52.7


Using the scaling format works every time, and no thinking. Just my $.02 worth.

Charlie Noah
Charles W. Noah Associates
[email protected]

The views and opinions expressed herein are my own (Charlie Noah) and do not necessarily reflect the views, positions or policies of any of my former, current or future employers, employees, clients, friends, enemies or anyone else who might take exception to them.


On 11-11-2010 12:14 PM, Simon Verona wrote:
Try

X=INT(X*20+.5)/20



=========================
Simon Verona
Director
Dealer Management Services Ltd

T: 0845 686 2300

Sent from my iPhone

On 11 Nov 2010, at 12:42, HARIPRASATH ILANGOVAN <[email protected]> wrote:

Hi,
 
            Please help to solve the roundoff problem. Let us take an example VAR.1 = '52.6766', now the second character to the decimal value is 7 which is greater than 5 so the result should be get like 52.65 and if the second decimal point is 4 instead of 7 then the output should be like 52.60. So the second decimal character should be roundoff between 0 and 5 only. I tried it by using the substring function and i am unable to replace it to the second character. Please help to proceed, coding part is given below for your reference.
 
    PROGRAM TEST.SUBSTRINGS
 
    $INCLUDE GLOBUS.BP I_COMMON
    $INCLUDE GLOBUS.BP I_EQUATE
    VAR.1 = '52.6766'
    VAR.2 = FIELD(VAR.1,".",2)
    VAR.3 = SUBSTRINGS(VAR.2,2,1)
    IF VAR.3 LT '5' THEN
        VAR.3 = '0'
    END ELSE
        VAR.3 = '5'
    END
* From  here i am strucking, to proceed further
    
END
 
 

Thanks and Regards,
Hari Prasath. D.I
--
Please read the posting guidelines at: http://groups.google.com/group/jBASE/web/Posting%20Guidelines
 
IMPORTANT: Type T24: at the start of the subject line for questions specific to Globus/T24
 
To post, send email to [email protected]
To unsubscribe, send email to [email protected]
For more options, visit this group at http://groups.google.com/group/jBASE?hl=en
--
Please read the posting guidelines at: http://groups.google.com/group/jBASE/web/Posting%20Guidelines
 
IMPORTANT: Type T24: at the start of the subject line for questions specific to Globus/T24
 
To post, send email to [email protected]
To unsubscribe, send email to [email protected]
For more options, visit this group at http://groups.google.com/group/jBASE?hl=en

--
Please read the posting guidelines at: http://groups.google.com/group/jBASE/web/Posting%20Guidelines
 
IMPORTANT: Type T24: at the start of the subject line for questions specific to Globus/T24
 
To post, send email to [email protected]
To unsubscribe, send email to [email protected]
For more options, visit this group at http://groups.google.com/group/jBASE?hl=en

<<attachment: cwnoah.vcf>>

Reply via email to