3
$\begingroup$

Consider this code:

ScientificForm[1., 8, NumberFormat -> (Row[If[#3 == "", {#1, "E", 0}, {#1, "E", #3}]] &)]
(* 1.E0 *)

ToString@ScientificForm[1., 8, NumberFormat -> (Row[If[#3 == "", {#1, "E", 0}, {#1, "E", #3}]] &)]
(* 1.E0E0 *)

Why is there an extra "E0" in the second output?

$\endgroup$
  • $\begingroup$ Use {#1, "E", "0"} instead of {#1, "E", 0}. $\endgroup$ – Silvia Dec 10 '13 at 4:15
3
$\begingroup$

I think you should use {#1, "E", "0"} instead of {#1, "E", 0}, or you can use ToString[#, StandardForm] &. But the former one is safer I think, cause I noticed a parameter other than integer will crash the kernel on my 9.0.1:

ScientificForm[1., 8, 
  NumberFormat -> (Row[
      If[#3 == "", {#1, "E", 1.2}, {#1, "E", #3}]] &)] // ToString
$\endgroup$
  • $\begingroup$ Thanks:) Do you know why ToString adds the extra "E0"? $\endgroup$ – xslittlegrass Dec 10 '13 at 6:27
  • $\begingroup$ @xslittlegrass I'm not sure. But ToString uses OutputForm by default, so this really is not about ToString, but about formatting. Maybe checking the underlying boxes will reveal some detail. $\endgroup$ – Silvia Dec 10 '13 at 7:15

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.