1

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;
xzczd
  • 65,995
  • 9
  • 163
  • 468
Juno
  • 13
  • 2

1 Answers1

1

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?

xzczd
  • 65,995
  • 9
  • 163
  • 468
  • Thanks! It really helps! :D The notations are quite different from MATLAB, but I am getting used to it. – Juno Sep 27 '21 at 14:06