s-news
[Top] [All Lists]

[S] The mysteries of round() and format()?

To: <s-news@wubios.wustl.edu>
Subject: [S] The mysteries of round() and format()?
From: "Paul Schwarz" <Paul.Schwarz@cornell.edu>
Date: Sun, 30 Jan 2000 19:36:48 -0500
Importance: Normal
Sender: owner-s-news@wubios.wustl.edu
Hi S-news readers,

I've been trying to use the round() function along the key() function to
display regression coefficients in the legend for a plot.  I'd like to
make sure that all the numbers are formatted to 3 decimal places so that
the numbers all line up in the legend columns.  Unfortunately, the
round() function does not do what I thought it would do (or at least not
what I'd like it to do).  For example:

> round(2,3)
[1] 2   # what I'd like is 2.000

> round(2.0202,3)
[1] 2.02  # what I'd like printed is 2.020

I've also tried usin the format() function -- also without success.  How
do I force the S-PLUS to print the numbers with the 3 decimal places
(including a trailing zero if need be) so that my number will line up in
my legend?

Thanks.

-Paul


Paul Schwarz
Department of Natural Resources
Cornell University
Fernow Hall
Ithaca, New York 14853-3001

-----------------------------------------------------------------------
This message was distributed by s-news@wubios.wustl.edu.  To unsubscribe
send e-mail to s-news-request@wubios.wustl.edu with the BODY of the
message:  unsubscribe s-news

<Prev in Thread] Current Thread [Next in Thread>