1
$\begingroup$

I am using MATLAB for a long time, and usually I express the number as exponential decimal such as

x = 1e2; % x=100

However, if I write this form in mathematica, it regards the e between 1 and 2 as a symbol (variable).

Do you guys know any expression using alphabet e for that, or should I change the form into using 10 such as

x=10^2;
$\endgroup$
4
  • 2
    $\begingroup$ I do not know of an equivalent to 1e2 except, perhaps, 1*^2. $\endgroup$
    – bbgodfrey
    Sep 19 at 14:51
  • 2
    $\begingroup$ Use: *^ In the documentation it's mentioned briefly in passing in ref/NumberMarks - also mentioned in tutorial/Numbers $\endgroup$
    – flinty
    Sep 19 at 14:53
  • $\begingroup$ @bbgodfrey, the expression 1e2 is general form in MATLAB. For example, 3e2 indicates 3 x 10^2. Similarly, 3.2e1 is 3.2 x 10^1 = 32. $\endgroup$
    – Juno
    Sep 27 at 14:05
  • $\begingroup$ @flinty, thanks for your answer. That helps :D $\endgroup$
    – Juno
    Sep 27 at 14:06
1
$\begingroup$

I'd say the best thing to do is to get used to the convention of Mathematica i.e. using 10^2 or 1*^2. Anyway, if you insist, one possibility is to make use of free form input by pressing Ctrl+=:

enter image description here

But to use free form input it's necessary to connect to the Internet and the interpretation may not always be correct, so a more robust solution is to define our own function:

SetAttributes[eScientificNumber, HoldAll];
With[{toreal = 
    If[$VersionNumber >= 12.3, Internal`StringToMReal, Internal`StringToDouble]}, 
  eScientificNumber[n_] := toreal@ToString@Unevaluated@n];

eScientificNumber /: MakeBoxes[eScientificNumber[n_], StandardForm] := 
 TemplateBox[{MakeBoxes@n}, "eScientificNumber", DisplayFunction -> (FrameBox@# &)]

The MakeBoxes[…] rule isn't necessary, it's just for the sake of aesthetic. The function name eScientificNumber is a bit too long to input repeatedly, so let's make use of input aliase and palette:

CurrentValue[$FrontEnd, "InputAliases"] = 
  Append[DeleteCases[CurrentValue[$FrontEnd, "InputAliases"], "esn" -> _], 
   "esn" -> MakeBoxes@eScientificNumber[\[SelectionPlaceholder]]];

CreatePalette[PasteButton@Defer@eScientificNumber[\[SelectionPlaceholder]], 
 WindowMargins -> Automatic]

You can even add your own keyboard shortcut as shown in e.g. this post but I'd like to stop here.

Now you can input 100 with 1e2 in following manners:

enter image description here

To understand the answer, you may want to read:

Preventing Superscript from being interpreted as Power when using Ctrl+^ shortcut?

Is Internal`StringToDouble broken in 12.3?

Make a custom object look like MatrixForm of a matrix?

$\endgroup$
1
  • $\begingroup$ Thanks! It really helps! :D The notations are quite different from MATLAB, but I am getting used to it. $\endgroup$
    – Juno
    Sep 27 at 14:06

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.