I would like to remove the leading zero and trailing decimal from the display of numbers in plots. For example, to get the correlation values to fit inside the cells of a correlation matrix, I can free up some space by removing all the leading zeros. So instead of 0.14
I would like .14
and instead of -0.28
I would like -.28
. I know that's not good formatting for the text of a paper, but for a plot this is more desirable in this case.
I would also like to remove the "." after 1.
.
I thought there would be options for this kind of output for NumberForm
, but they are not documented if they do exist. Currently I'm using this formatting function:
FormatCorrelations[n_] := If[NumberQ[n], NumberForm[n, {2, 2}, ExponentFunction -> (Null &), NumberPadding -> {"", ""}], n];
I would like to keep all those options (specifying the significance and number of decimals, preventing exponential notation, and ignoring string inputs) while additionally removing the leading zeros and trailing decimals.
I found one answer for the trailing decimal in this questions, but it doesn't work me (breaks the code).
I also found this answer to remove the trailing decimal: NumberForm[# /. x_ /; x == 1 -> 1, 2]
, but it fails to remove the decimal when I apply it via my function.
1.
be formatted differently than1.0001
? Because the former will be1
and the latter1.00
. $\endgroup$1. -> 1
and1.0001 -> 1.00
according to what I'm looking for. That may be inappropriate for some uses, but I am only using this formatting for proportions and correlations, so it is not an issue for me. $\endgroup$