Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.soft-sys.math.mathematica > #10463 > unrolled thread
| Started by | James Stein <mathgroup@stein.org> |
|---|---|
| First post | 2012-06-14 09:36 +0000 |
| Last post | 2012-06-14 09:36 +0000 |
| Articles | 1 — 1 participant |
Back to article view | Back to comp.soft-sys.math.mathematica
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: ToString Awkwardness James Stein <mathgroup@stein.org> - 2012-06-14 09:36 +0000
| From | James Stein <mathgroup@stein.org> |
|---|---|
| Date | 2012-06-14 09:36 +0000 |
| Subject | Re: ToString Awkwardness |
| Message-ID | <jrcbbf$dtv$1@smc.vnet.net> |
Here are two routines I wrote long ago.
Perhaps they'll be a bit of help...
jhsForm::usage="jhsForm[r,n] -> returns a string to display r with n digits
after the decimal point. If n is larger than the accuracy of the number, n
will be truncated. If n <= 0, 0 will be used.
jhsForm[r,n,w,padChar] ->is as above, except the string will be a least w
characers in width, prepadded with padChar if necessary.";
jhsForm[r_, fD_Integer: - 1] := Module[{nd = 999, fd},
(* nd,fd are arguments to 'NumberForm' *)
(*
fd := # places to right of decimal point *)
If[Abs[r] == Infinity,
Return[If[Sign[r] > 0, "=E2=88=9E", "-=E2=88=9E"]]];
If[fD >= 0,
fd = fD,
fd = Max[Min[Accuracy[r], 2]];
];
If[fd == 0,(* elide decimal point: *)
Return[ToString[Round[r]]],
Return[ToString[NumberForm[r // N, {nd, fd}]]];
];
];
jhsForm[r_, fD_: - 1, fW_: 0, pad_: " "] := Module[{s},
s = jhsForm[r, fD];
While[StringLength[s] < fW, s = pad <> s];
s
];
On Wed, Jun 13, 2012 at 1:55 AM, Kevin J. McCann <kjm@kevinmccann.com>wrote:
> I have several plots with annotation that includes parameter values. I
> am using ToString inside a Text command to do this, and all is well
> unless the values are small so that the results are in scientific
> notation. When this happens, I get something like this:
>
> "f(x) = " <> ToString[8.71 10^-15]
>
> f(x) = -15
> 8.71 10
>
> Which is a bit awkward looking in the plot. Upon further investigation,
> I looked at the FullForm of the above and got:
>
> "f(x) = -15\n8.71 10"
>
> So, I see why the output "looks funny". The exponent is treated
> separately from the 10. Any suggestions for nicer looking output?
>
> Thanks,
>
> Kevin
>
>
Back to top | Article view | comp.soft-sys.math.mathematica
csiph-web