Recently I wanted to find the difference between two numbers and report
the output with only two decimal places. I don't know how to round off
a number like:
3.6666667
to
3.67
Can someone tell me the function to do this or show me an example of a
'write' statement which will do the rounding automatically?
Just in case it isn't obvious, here is what I'm trying to do. Let's say
I have a simple REXX program named calcdiff.bat which is simply:
/* calcdiff.bat */
parse arg start stop
elapsed = stop - start
say elapsed
rndelp=round(elapsed,2)
say rndelp
So if I type:
run calcdiff .333333 1 ('run' is my batch file which runs REXX)
It displays:
.666667
.67
Where 'round' is my guess at the name of the function to round off a
floating point number.
--
Don Ramm, QUALCOMM Incorporated, San Diego CA
619-658-2597, dr...@qualcomm.com
DR> I don't know how to round off a number like:
DR> 3.6666667
DR> to
DR> 3.67
DR> Can someone tell me the function to do this or show me an example
DR> of a 'write' statement which will do the rounding automatically?
Format(number,,2)
Ave,
Andre Doff
ad...@ibm.net
/* indicates rexx */
trace o /* trace r/i is good - o is off */
/* */
/* */
values = '3.1234 3.5123 3.5789 3.6667'
do i = 1 to words(values)
say word(values,i) '=' format(word(values,i),1,2)
end
Ready;
test1
3.1234 = 3.12
3.5123 = 3.51
3.5789 = 3.58
3.6667 = 3.67
Ready;
sp con stop close
The 2nd parameter defines the number of positions to the left of the
decimal. The 3rd parameter defines the number of positions to the right
of the decimal with the rounding taking place automatically using the
next position right of the decimal as the base for the rounding.
Jon
The FORMAT() built-in functions provides thae ability to round numbers
for you.
FORMAT( number[, [before][, [after]
[ ,expp][ ,expt]]]] )
Returns number rounded and formatted with before and
after specifying the size of the integer and fraction parts
respectively. Expp specifies the number of places for the
exponent and expt specifies the trigger point for the use
of exponential notation. If before is not large enough to
contain the integer part of number an error results.
Example: with x = 123.456
123.45 = FORMAT( x, 3, 2 )
123E+2 = FORMAT(x,3,2,1,1)
-----------------------------------------------------------------------
Dick Goran author, REXX Reference Summmary Handbook
C F S Nevada, Inc. Contributing Editor. OS/2 Magazine
953 E. Sahara Ave, Suite 9B [OS/2 Advisor]
Las Vegas, NV 89104-3012 CompuServe: 71154,2002
702-732-9616 Voice Internet: dgo...@cfsrexx.com
702-732-3847 FAX
http://www.cfsrexx.com
(see our new OS/2 game - CFSPoker)
Look at the Format instruction : Say Format(3.666667,,2) should display 3.67
From memory Format(number,before,after) where before and after are the
number of digits you want before and after the decimal point. Other parameters
may control the exponent part but I do not use them so memory is of no use...
JPierre