1
$\begingroup$

I have a function which is given below. If my number, n is 0. or 1. the function gives 0.E0 or 1.E0, respectively. However, I would like to form it as 0.0000E0 or 1.0000E0 like the other numbers given in the function. How could I solve this problem ?

f[n_] := ScientificForm[N[n], NumberFormat -> (Row[{#1, "e", If[#3 == "", "0", #3]}] &)];

Thank you.

$\endgroup$
1
$\begingroup$

Perhaps something like this?

Clear[f]
f[n_, w_Integer /; Positive[w]] :=
  PaddedForm[N[n], {w, w},
    NumberPadding -> {"", "0"},
    NumberFormat -> (Row[{#1, "e", If[#3 == "", "0", #3]}] &)]

Then

f[#, 2] & /@ Range[0, 1, .25]

{0.00e0, 0.25e0, 0.50e0,0.75e0, 1.00e0}

and

f[#, 5] & /@ Range[0, 1, .25]

{0.00000e0, 0.25000e0, 0.50000e0, 0.75000e0, 1.00000e0}

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.