0
votes

In Mathematica, what is the easiest way to print a given approximate number using E-notation with a specified accuracy? For example given:

a = 1.23456789 10^-23

how can a be printed to 3 significant digits to get:

1.23E-23

Notice that trying FortranForm[] with N[] does not work since N[] will not truncate an approximate number.

2

2 Answers

0
votes

After some playing around I found an answer:

NumberForm[a, {5, 3}, NumberFormat -> (SequenceForm[#1, "E", #3] &), ExponentFunction -> (# &)]

If you want to make this more robust and be able to handle rational numbers as well, replace a by N[a,3] .

Notice that the ExponentFunction is needed since a number like 1.2345 would be outputted as 1.23E .

0
votes

You may use ScientificForm with the NumberFormat option.

With

a = 1.23456789 10^-23;

Then

ScientificForm[a, 3]
1.23*10^(-23)

The output can be further formatted to you spec with the NumberFormat option.

ScientificForm[a, 3, NumberFormat -> (Row[{#1, "E", #3}] &)]
1.23E-23

Hope this helps.