Re: exponential format
- To: mathgroup at smc.vnet.net
- Subject: [mg114039] Re: exponential format
- From: Maxim <m.r at inbox.ru>
- Date: Mon, 22 Nov 2010 07:34:32 -0500 (EST)
- References: <ic34m8$5jt$1@smc.vnet.net>
On Nov 18, 6:03 am, Magdalena Moczydlowska
<magdamoczydlow... at gmail.com> wrote:
> Hi,
>
> Maybe my question is silly but I can not find any answer in the net ?
> How to change in Mathematica a normal number format to exponential
> notation. I mean for example 0.25->6.25e-02.
>
> Thank you for any suggestion,
> Magdalena
You can play with the options of NumberForm or use the Java format()
method:
NumberForm[0.0625, NumberFormat -> (Row[{#, "e", #3}]&),
ExponentFunction -> (#&)]
Needs["JLink`"]
sprintf[fs_String, s__] := Module[
{vararg, n = Length@ {s}},
InstallJava[];
LoadJavaClass["java.lang.String"];
LoadJavaClass["java.lang.reflect.Array"];
Quiet@ JavaBlock[
vararg = JavaNew["[Ljava.lang.Object;", n];
java`lang`reflect`Array`set[
vararg, # - 1, MakeJavaObject@ {s}[[#]]
]& /@ Range@ n;
java`lang`String`format[fs, vararg]]]
sprintf["%.2e", .0625]
Maxim Rytin
m.r at inbox.ru