Consider the following example:


  round-mode = places,
  round-precision = 4

  \cs_new_eq:NN \calc \fp_eval:n






Is it possible to remove the trailing zeros from the numbers? (In this case it means getting 3.5 instead of 3.5000 and 1.75 instead of 1.7500.)


It seems that it's not possible to achieve what I would like; should the question therefore be closed?

  • 1
    You've asked for 4 places of precision: that's what you've got
    – Joseph Wright
    Commented Jan 11, 2014 at 14:04
  • @JosephWright The problem is that I would like the numbers with no trailing zeros to have four decimals precision. Commented Jan 11, 2014 at 14:06
  • 2
    Those numbers do have four decimal place precision. The trailing zeroes in 3.5000 signal that the true value is between 3.49995 and 3.50005. Think carefully about why you want to remove them. Commented Jan 11, 2014 at 14:24
  • 2
    Remember: siunitx is a package for dealing with physical measurements and quantities. You can't have 7/2 cm or whatever: you can have 3.5000 cm with an uncertainly in as @EthanBolker suggests. Also, if you really want to print a fraction within say \SI then parse-numbers = false is available.
    – Joseph Wright
    Commented Jan 12, 2014 at 9:41
  • 2
    @SvendTveskæg I will see what I can come up with in the next release, of course!
    – Joseph Wright
    Commented Jan 12, 2014 at 9:46

4 Answers 4


You can use xintfrac. The package should have a native variant to its \xintTrunc or \xintRound routines which would strip trailing zeros, for lack of it I wrote a quick hack.

This initial hack was not completely satisfying (bad handling of integers). Here are two methods.

Update: the second method now allows two optional parameters, the first one is the number of digits after decimal mark (default 4), the second one is the decimal mark (default .). And this is expandable.


% \usepackage[
%   round-mode = places,
%   round-precision = 4
% ]{siunitx}

  \cs_new_eq:NN \calc \fp_eval:n



% quickly written, there might be a simpler way
% you can modify \myNum@ to replace the dot by a comma if you prefer
% this method will work up to nine fixed point digits after decimal mark
% works also with negative numbers

% \def\myNum@ #1.{\the\numexpr #1.}% <- replace the last dot by the sep
%                                 % you need
% \newcommand*{\myNum}[1]{\xintRev{\expandafter\expandafter\expandafter
%                                  \myNum@\xintRev{\xintRound{4}{#1}}}}

% but this had problems: would not handle well the case of integers, and even
% crash on zero, (\xintRound then does not print 0.0000 but just 0 without a
% dot). Here are now two general methods:

% method allowing customizing on output of the decimal mark:
% (but needs some modifications to switch from 4 to another number of digits)
                        \romannumeral0\xintround {4}{#1}0000\relax }
\def\myNum@ #1{\if#10\expandafter\myNum@zero\fi \myNum@@ #1}
\def\myNum@@ #1.#20000#3\relax{\ifx\relax#2\relax \expandafter\myNum@int\fi
                               #1,#2}% <- we use a comma as decimal mark
% as comma was used above, must also be used here:
\def\myNum@int #1,{#1}% <- case of an integral number (positive or negative)
\def\myNum@zero #1\relax{0}% <- case of zero                          

% another way, easily generalized to any given number of digits,
%  (actually, generalization already done: nb of digits is optional arg)
% \newcommand*{\myNumVar}[2][4]{\expandafter\expandafter\expandafter
%                            \myNumVar@\xintREZ{\xintRound {#1}{#2}}}
% \def\myNumVar@ #1/1[#2]%
% {\xintifSgn {#2}{\xintTrunc {-#2}{#1[#2]}}{#1}{\xintNum{#1[#2]}}}

% now allows arbitrary separator as second optional argument:

% **** and is expandable! ****

\catcode`_ 11
\def\myNumVar #1{\myNumVar_chkopta #1\Z }
\def\myNumVar_chkopta #1{\ifx [#1\expandafter\myNumVar_opta
                         \fi #1}
\def\myNumVar_noopta #1\Z {\expandafter\expandafter\expandafter
                           \myNumVar@\xintREZ{\xintRound {4}{#1}}.}
\def\myNumVar_opta [\Z #1]#2{\myNumVar_chkoptb #2\Z {#1}}
\def\myNumVar_chkoptb #1{\ifx [#1\expandafter\myNumVar_optb
                         \fi #1}
\def\myNumVar_optb [\Z #1#2]#3{\expandafter\expandafter\expandafter
                           \myNumVar@\xintREZ{\xintRound {#1}{#3}}{#2}}
\def\myNumVar_nooptb #1\Z #2{\expandafter\expandafter\expandafter
                           \myNumVar@\xintREZ{\xintRound {#2}{#1}}.}
\catcode`_ 8

\def\myNumVar@ #1/1[#2]#3%
    {\xintifSgn {#2}{\expandafter\expandafter\expandafter
                     \myNumVar@@ \xintTrunc {-#2}{#1[#2]}.{#3}}%

\def\myNumVar@@ #1.#2.#3{#1#3#2}



\verb|\myNum| uses a comma on output:



\verb|\myNumVar| has an optional argument to specify the number of digits
(possibly zero) after the dot as decimal mark:

\multido{\i=2+1}{5}{\myNumVar [12]{\horse{\i}}\quad}

\multido{\i=2+1}{5}{\myNumVar [12]{\horsenegative{\i}}\quad}

\multido{\i=2+1}{5}{\myNumVar [0]{\horse{\i}}\quad}

\multido{\i=2+1}{5}{\myNumVar [0]{\horsenegative{\i}}\quad}

\verb|\myNumVar| has a \textbf{second} optional argument to specify the

\multido{\i=2+1}{5}{\myNumVar [12][,]{\horse{\i}}\quad}

\multido{\i=2+1}{5}{\myNumVar [12][,]{\horsenegative{\i}}\quad}

If you want to use crazy things like [ itself as separator you can do it:

\verb|\myNumVar [12][[]{stuff}|

\multido{\i=2+1}{5}{\myNumVar [12][[]{\horse{\i}}\quad}

But with ], use braces

\verb|\myNumVar [12][{]}]{stuff}|

\multido{\i=2+1}{5}{\myNumVar [12][{]}]{\horse{\i}}\quad}

Integral numbers do not have a decimal mark:

\myNum {-3.0000}=\myNumVar [5]{-3.0000}

\myNum {0.0000}=\myNumVar [13][!]{0.0000}

\myNum {-300.0000}=\myNumVar [7][;]{-300.0000}

\verb|\myNumVar| is expandable:\edef\test {\myNumVar [17][;]{1/1250}}

\verb|\edef\test {\myNumVar [17][;]{1/1250}}\meaning\test|


removal of zeroes

  • I say this works with negative numbers, but there would be a problem with -3.0000, I don't have time to fix this now. Will provide complete solution later. (also I need to know if in case of 3.0000 the wanted thing is 3 or 3.).
    – user4686
    Commented Feb 11, 2014 at 12:08
  • 3.0000 --> 3. Thank you for the solution (and your upcomming improvement)! Commented Feb 11, 2014 at 12:18
  • @SvendTveskæg glad if it helps. I have replaced the initial slightly deficient hack by two methods. In the second method too, it would not be that hard now to add one extra layer to replace the dot by anything you want as decimal mark (on output).
    – user4686
    Commented Feb 11, 2014 at 14:29
  • Really nice. If you would generalize it to be abel to take both . and , as decimal separator, it would be really cool. :) Commented Feb 11, 2014 at 14:33
  • @SvendTveskæg I have extended the second method to allow to specify the separator as a second optional argument. Notice that both the first and now the second method are completely expandable macros.
    – user4686
    Commented Feb 11, 2014 at 16:07

Since v3.0 from 2021 there is a option round-pad which seems to do what you want:


  round-mode = places,
  round-precision = 4,
  round-pad = false %% true by default

  \cs_new_eq:NN \calc \fp_eval:n






enter image description here


A recommended solution with fp package.



enter image description here

  • Can I get a comma as decimal separator instead of a full stop? Commented Jan 12, 2014 at 10:07
  • @SvendTveskæg: Yes, just pass it to \num with your siunitx settings. Expansion should be carefully considered, ask other people in the chat room to fix the expansion problem if you want to pass the value to \num. Commented Jan 12, 2014 at 10:19
  • 3
    Recommended by whom? If it's you that recommend it, just avoid saying it: presenting the solution is sufficient. Otherwise tell who's recommending the solution.
    – egreg
    Commented Jan 12, 2014 at 12:19
  • @egreg: By myself of course. Commented Jan 13, 2014 at 14:28

You asked,

Is it possible to remove the trailing zeros from the numbers?

Piece of cake with LuaLaTeX -- no need for the siunitx package and its \num macro. :-)

enter image description here


\usepackage{luacode} % for '\luaexec' macro 
% Create 2 Lua functions, 'horse' and 'mynum':
  function horse ( i )
    return ( 3.5 * math.sin ( math.pi / i ) )
  function mynum ( j  )
    return ( string.format ( '\%.5g' , j ) )
% Create a LaTeX wrapper macro for 'mynum' function:


\directlua { for i=2,6 do 
               tex.sprint ( mynum ( horse ( i ) ) .. '\\quad' )

You must log in to answer this question.

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