I have some numbers output from Matlab and I want to show them as tables in LaTeX. The numbers are in the form 0.14190949656253118000 or 0.01234e-3 and I want to show them in scientific notation. How can I find/write, a macro that is called like \scn{0.14190949656253118000} or \scn{0.01234e-3} and results in $1.41x10^{-1}$ or $1.23x10^{-5}$. Note that the number of digits after the decimal points should be configable.

2 Answers 2


Working from Boris' answer:




enter image description here

However, for your particular number, siunitx versions lower than 2.4n return a "number too big" error unless you round the number off (as you had originally indicated, but I forgot about). That prompted me to write the following MATLAB function that will print the LaTeX code for your numbers to whatever precision you want:

function s=pp(x,n)
% pretty-print a value in scientific notation
% usage: s=pp(x,n)
% where: x a floating-point value
%        n is the number of decimal places desired
%        s is the string representation of x with n decimal places, and
%          exponent k
exponent=floor(log10(abs(x))); %to accomodate for negative values
s=sprintf('$%*.*f \\times 10^{%d}$',n+3,n,mantissa,exponent);
% returns something like '$1.42 \times 10^{-1}$'


>> s1=pp(0.14190949656253118000,2)
s1 =
$1.42 \times 10^{-1}$
>> s2=pp(0.01234e-3,3)
s2 =
$1.234 \times 10^{-5}$

But again, any recent version of siunitx and Boris' answer will work fine for rounded numbers, and siunitx 2.4n will work fine even without rounding.

  • Which version of siunitx do you have? You should not get the 'too big' error with the latest release.
    – Joseph Wright
    Apr 4, 2012 at 7:29
  • I'll update and check again. Apr 4, 2012 at 11:52
  • Updated from CTAN, got siunitx 2.4l, same problem. Updating answer with new details. Apr 4, 2012 at 12:52
  • Ah, that's not quite what I tried :-) The question indicates that the output should be rounded (which was where there used to be a bug with the number of digits in the mantissa!). So I both rounded and forced scientific notation, which works fine. I will investigate this other issue when I get a moment.
    – Joseph Wright
    Apr 4, 2012 at 12:59
  • Yep. Forgot the rounding, which Boris remembered to include. Apr 4, 2012 at 13:20

The macro \num from, e.g. siunitx does just this. For example


enter image description here

Note that too many digits in the input may lead to error "Number is too big".

Also, the optional arguments in \num can be set for all numbers using \sisetup.

  • 2
    It would be better to show a complete example. By default \num{0.14190949656253118000} produces 0.141 909 496 562 531 180 00} Apr 4, 2012 at 0:47
  • ok, added some examples
    – Boris
    Apr 4, 2012 at 1:43
  • Thanks Boris, I just defined a macro like this \newcommand{\sn}[1]{\num[round-precision=2,round-mode=figures,scientific-notation=true]{#1}} since I want to make the numbers consistent throughout the document.
    – Helium
    Apr 4, 2012 at 2:39
  • 9
    easier to say \sisetup{round-precision=2,round-mode=figures,scientific-notation=true}, and then just user \num.
    – Boris
    Apr 4, 2012 at 3:03

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .