# Padding decimal output with ending zeros

I want to pad with ending zero and tried the following code

d = 7;
f[x_] := 150/x
g[x_] := 2 Log[x] - 3
StringPadRight[ToString[NumberForm[N[g[x]], d]], d, "0"]}, {x, 20,
50}] // N // TableForm


which gave

 20. 7.50000 2.99146
21. 7.14285 3.08904
22. 6.81818 3.18208
23. 6.52173 3.27098
24. 6.25000 3.35610
25. 6.00000 3.43775


which is kind of 'OK'.

Are there any better/shorter code to get this result?

Also, is there a simple way to remove the period for the integers in the first column?

• Maybe define: numb[n_] := NumberForm[N[n, d], d] then do Table[{x, numb@f[x], numb@g[x]}, {x, 20, 50}] // TableForm Nov 19 '20 at 13:04
• That worked well, thank you. Perhaps make it an answer?
– mf67
Nov 19 '20 at 15:45
• This might be better: DecimalForm[Table[{x, N[f[x]], N[g[x]]}, {x, 20, 50}], {d, d - 2}]. Among other things it will get the rounding correct. Nov 19 '20 at 16:44