Re: [R] format a number

From: jim holtman <jholtman_at_gmail.com>
Date: Mon, 10 Mar 2008 06:48:13 -0500

You can also use sprintf:

> v = c(0.43554, -0.22343)

> sprintf("%.2f", v)

[1] "0.44" "-0.22"
>

On 3/10/08, Martin Kaffanke <technik_at_roomandspace.com> wrote:
> Hi there!
>
> I have i.e. v = c(0.43554, -0.22343), and so on. Now I'd like to make a
> format like
>
> format(v, digits=2) but without the leading 0, so 0.43554 becomes .44,
> -0.22343 becomes -.22
>
> How can I do that?
>
> runnable example for copy and paste:
>
> v = c(0.43554, -0.22343)
> format(v, digits=2)
>
> Thanks,
> Martin
>
> --
> Ihr Partner für Webdesign, Webapplikationen und Webspace.
> http://www.roomandspace.com/
> Martin Kaffanke +43 650 4514224
>
> ______________________________________________
> 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.
>
>
>

-- 
Jim Holtman
Cincinnati, OH
+1 513 646 9390

What is the problem you are trying to solve?

______________________________________________
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 10 Mar 2008 - 11:52:42 GMT

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 10 Mar 2008 - 12:30:21 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