I have a code where I used NumberForm[i] where i can be an integer or rational number. I would like the output to have the same digits as in i. minimal example:
Table[NumberForm[i], {i, 0., 0.05, 0.01}]
{0.,0.01,0.02,0.03,0.04,0.05}
The first element shows only one digit 0. I want it to be 0.00 same digits as the rest. I know that for this case it can be done like this
Table[NumberForm[i, {2, 2}], {i, 0., 0.05, 0.01}]
{0.00,0.01,0.02,0.03,0.04,0.05}
but then I need to change the second element of {2,2} every time the digits of i change, e.g.
Table[NumberForm[i, {2, 1}], {i, 0, 0.5, 0.1}]
{0.0,0.1,0.2,0.3,0.4,0.5}
How can I automatically make the digits in the output the same as the step size of i?
Tablemakes this impractical, and I think it is perhaps not representative of your actual usage. The only way you could do this is if the formatting function had access to ALL your numbers at once, so it can determine how many digits are needed overall, and apply them uniformly. In comments below you also mentioned that your numbers come from a dataset and are not generated programmatically, so please update the question with an example more closely resembling your application. $\endgroup$