I need to convert some numeric values to characters. I want to show trailing zeros if relevant, and no decimal place if the number is an integer. For example, in the code below, I need my output to be "11" "0.30" "0.00050" "3.1" "4.6". How do I get the 11 to display as "11" not "11."?
sprintf('%#.2g', c(11, 0.301, 0.000502, 3.12, 4.56))