Re: [R] Pretty printing numbers

From: Henrique Dallazuanna <wwwhsd_at_gmail.com>
Date: Sun, 08 May 2011 21:06:43 -0300

formatC(round(2189.745, 2), big.mark=",",format="f", drop0trailing = TRUE)

On Sun, May 8, 2011 at 9:02 PM, Worik R <worikr_at_gmail.com> wrote:
>> formatC(round(2189.745, 2), big.mark=",",format="f")
> [1] "2,189.7400"
>
> Unfortunately this does not work
>
> Worik
>
> On Mon, May 9, 2011 at 11:45 AM, Peter Langfelder <
> peter.langfelder_at_gmail.com> wrote:
>
>> On Sun, May 8, 2011 at 4:41 PM, Worik R <worikr_at_gmail.com> wrote:
>> > Friends
>> >
>> > I am trying to format a number to a string so 2189.745 goes to "2,189.35"
>> > and 309283.929 goes to "309,283.93"
>> >
>> > I have tried to use formatC(X, big.mark=",",drop0trailing=FALSE,
>> format="f")
>> > but it does not get the number of decimals correct.  Specifying digits
>> does
>> > not work as that is significant digits.  I could use a switch statement
>> > switching on the size of the number to be formated to set the digits
>> > parameter but that is complex and leaves me insecure that thre may be
>> other
>> > problems I have not uncovered.
>> >
>> > Is there a simple way of using library functions to insert big.marks and
>> get
>> > the number of trailing digits correct?  Perhaps some way of using
>> sprintf?
>> >
>>
>> Try this inserting a round() step before the final printing:
>>
>> x = 309283.929
>>
>> formatC(round(x, 2), big.mark=",",drop0trailing=TRUE, format="f")
>>
>> [1] "309,283.93"
>>
>>
>> HTH,
>>
>> Peter
>>
>>
>> > cheers
>> > Worik
>> >
>> >        [[alternative HTML version deleted]]
>> >
>> > ______________________________________________
>> > R-help_at_r-project.org mailing list
>> > https://stat.ethz.ch/mailman/listinfo/r-help
>> > PLEASE do read the posting guide
>> http://www.R-project.org/posting-guide.html
>> > and provide commented, minimal, self-contained, reproducible code.
>> >
>>
>>
>>
>> --
>> Sent from my Linux computer. Way better than iPad :)
>>
>
>        [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help_at_r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O

______________________________________________
R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Received on Mon 09 May 2011 - 00:17:22 GMT

This quarter's messages: by month, or sorted: [ by date ] [ by thread ] [ by subject ] [ by author ]

All messages

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Mon 09 May 2011 - 00:30:05 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive