format.float | R Documentation |
format.float
prepares numbers for results printing.
## S3 method for class 'float' format(x, digits = 2)
x |
Value to be formatted. Input can be a numeric or character value. |
digits |
Number of fixed digits, after decimal point |
This function formats numbers with the given number of decimal digits.
Numbers are always assumed to be double
.
If there is a percent sign in x
, it is removed prior to formatting.
Returns a character value.
Felipe Figueiredo
format.float(0.5) format.float(0.672, 4) format.float(1.4927, 1) format.float(c(1.756, 1.823)) # Input is character format.float("1.12543") format.float(c("1.756", "1.823")) # Input is percentage format.float("10%", 1) format.float("15 %", 1) # Useful for data frames DF <- data.frame(num = c(1.756, 1.823), char = c("1.756", "1.823"), stringsAsFactors = FALSE) transform(DF, num = format.float(num), char = format.float(char))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.