Convert p-values to a compact textual representation. The function prints decimals up to the first non-zero decimal and the following one, applying standard rounding.
Details
The number of decimals shown depends on the magnitude of the p-value so that two meaningful digits are displayed after the leading zeros.
Specifically:
For \(p \ge 0.1\), two decimal places are shown.
For \(0.01 \le p < 0.1\), three decimal places are shown.
For \(0.001 \le p < 0.01\), four decimal places are shown.
For \(0.0001 \le p < 0.001\), five decimal places are shown.
For \(p < 0.0001\), the string
"<0.0001"is returned.
This formatting ensures that the first non-zero decimal of the \(p\)-value and the following digit are displayed, while avoiding an excessive number of leading zeros.
If add.p = TRUE, the prefix "*p*=" (or "*p*<" when applicable) is added to the formatted value.
This will ensure the p appears in cursive when calling the function in line on R markdown documents.