2
$\begingroup$

Related to but different from this question.

I'd like my InputField to display scientific notation not only for numbers larger than one million, but also for smaller numbers. Mathematica (version 10.3 on 64-bit Linux Mint) shows any number larger than 10^6 in scientific notation (whether in an InputField or outside). I want to set this threshold to be lower, at least across all InputField controls in a given module.

What I've tried is to use ScientificForm inside an InputField, but this causes it to look funny.

DynamicModule[{x},
 Grid[{
   {Manipulator[Dynamic[x], {10^5, 2*10^6}]},
   {InputField[Dynamic[ScientificForm[x, 2]]]},
   {InputField[Dynamic[x, 2]]}
   }]
 ]

Output of code above

When sliding beyond 10^6, it looks like:

Output after sliding beyond 10^6

I would like to have the same precision as the top InputField across all number ranges, while keeping the formatting as the second InputField, without the quotes. I thought I might be able to use $PrePrint but I wasn't sure how. I'd appreciate any help getting this to work.

$\endgroup$

2 Answers 2

2
$\begingroup$

One can simply set the ShowStringCharacters->False option in the Style of the InputField:

DynamicModule[{x}, 
 Grid[{
  {Manipulator[Dynamic[x], {10^5, 2*10^6}]},
  {InputField[Dynamic[Style[ScientificForm[x, 2], ShowStringCharacters -> False]]]},
  {InputField[Dynamic[x, 2]]}
  }]
 ]

enter image description here

compare also this answer: https://mathematica.stackexchange.com/a/6294/45128

$\endgroup$
1
$\begingroup$

I've succeeded in doing this to my satisfaction. It's rather crude, and uses Defer to keep the number in exponent form. There may be a more elegant way to do this (comments appreciated), but this works for simple cases.

ScientificFormNumber[x_, precision_] := Block[{mantissa, exponent},
   {mantissa, exponent} = MantissaExponent[x];
   N[Round[(mantissa*10*10^(precision-1))]/10^(precision-1)]*
    Defer[10]^(exponent - 1)
 ];

DynamicModule[{x},
 Grid[{
   {Manipulator[Dynamic[x], {10^5, 2*10^6}]},
   {InputField[Dynamic[ScientificForm[x, 2]]]},
   {InputField[Dynamic[ScientificFormNumber[x, 2]]]},
   {InputField[Dynamic[x, 2]]}
   }]
 ]

Output of above code

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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