Skip to content
Prev 278799 / 398502 Next

format numbers without leading or trailing 0s

A simple question, but I can't find something to do what I want:

Given: a vector of numbers, like

lambda <- c(0, 0.005, 0.01, 0.02, 0.04, 0.08)

Desired: format them in minimal space for use as plot labels, ie, 
without leading or tailing 0s. For this example:

lambdaf <- c("0", .005", ".01", ".02", ".04", ".08")