This question is very closely related to two earlier ones:
Rounding to the nearest decimal
and
How do you round numbers so that it affects computation?
but confronts an additional issue not addressed by those answers. (Incidentally, the only way you can appreciate my question is by running code on your machine... merely inspecting the below does not suffice.)
I want to generate a fixed list of random numbers (from a distribution, but the below illustrates the problem), but for space and readability, I want to keep only three digits to the right of the decimal point. This code
Round[#, .001] & /@ RandomReal[{1, 10}, 3]
gives the following output (which I typed in by hand):
(* {9.41, 7.26, 4.298} *)
This looks fine. However, if you simply copy everything from that output cell and it paste into an input cell, you get "`" markers after each number, and in some cases many more digits than the three desired.
I've tried all manner of Round
, Ceiling
and Floor
, such as:
N@(Round[1000 #] & /@ RandomReal[{1, 10}, 3])/1000
and
myRound[x_, n_] := Ceiling[10^n x]/10^n // N;
myRound[#, 3] & /@ RandomReal[{1, 10}, 3]
and can get appropriate outputs, which show three digits, as desired. Nevertheless, in every case when I cut such output and paste it into an input cell, the "`" markers or extraneous digits appear.
How do I get lists of "true" fixed-digit numbers for input cells?
ToString
be acceptable? $\endgroup$NumberForm[RandomReal[], {Infinity, 3}]
. $\endgroup$