A generalization of my original function is possible here. (I decided that this is not equivalent to Mr. Master’s decision, but I’m still not sure which, in my opinion, is better.)
re = RegularExpression;
(* Show Number. Convert to string w/ no trailing dot. Use at most d significant
figures after the decimal point. Target t significant figures total (clipped
to be at least i and at most i+d, where i is the number of digits in integer
part of x). *)
shn[x_, d_:5, t_:16] := ToString[x]
shn[x_?NumericQ, d_:5, t_:16] := With[{i= IntegerLength@IntegerPart@x},
StringReplace[ToString@NumberForm[N@x, Clip[t, {i,i+d}],
ExponentFunction->(Null&)],
re@"\\.$"->""]]
Testing:
Here we indicate 4 significant digits, but never discard them to the left of the decimal point and never use more than two significant digits to the right of the decimal point.
(
{123456, 1234.4567, 123.456, 12.345, 1.234, 1.0001, 0.123, .0001234}
{ 123456 -> "123456",
1234.456 -> "1234",
123.456 -> "123.5"
12.345 -> "12.35",
1.234 -> "1.23",
1.0001 -> "1",
0.123 -> "0.12",
0.0001234 -> "0.00012" }
source
share