Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

show0

Convert Numbers into Text with Specified Decimal Places


Description

Return a character representation of a number with added zeroes out to a specified number of decimal places.

Usage

show0(x, n, add2int=FALSE, round2n=FALSE)

Arguments

x

numeric data (scalar, vector, or matrix).

n

number of decimal places to show, including zeroes.

add2int

if TRUE, add zeroes to integers after the decimal.

round2n

if TRUE, round x first to n decimal places.

Value

A scalar/vector of strings representing numbers. Useful for labelling purposes.

Note

By default, this function does not round or truncate numbers. It simply adds zeroes if n is greater than the available digits in the decimal part of a number. The user can choose to round the numbers first by setting argument round2n = TRUE.

Author(s)

Rowan Haigh, Pacific Biological Station, Fisheries and Oceans Canada, Nanaimo BC

See Also

Examples

local(envir=.PBSmodEnv,expr={
  oldpar = par(no.readonly=TRUE)
  frame()

  #do not show decimals on integers
  addLabel(0.25,0.75,show0(15.2,4))
  addLabel(0.25,0.7,show0(15.1,4))
  addLabel(0.25,0.65,show0(15,4))

  #show decimals on integers
  addLabel(0.25,0.55,show0(15.2,4,TRUE))
  addLabel(0.25,0.5,show0(15.1,4,TRUE))
  addLabel(0.25,0.45,show0(15,4,TRUE))
  par(oldpar)
})

PBSmodelling

GUI Tools Made Easy: Interact with Models and Explore Data

v2.68.8
GPL (>= 2)
Authors
Jon T. Schnute [aut], Alex Couture-Beil [aut], Rowan Haigh [aut, cre], Nicholas Boers [ctb], Anisa Egeli [ctb], A. R. Kronlund [ctb], Steve Martell [ctb], Norm Olsen [ctb]
Initial release
2019-03-12

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.