4

I have a macro that uses the siunitx package to format decimal numbers as percentages. It looks like this:

\documentclass{article}
\usepackage{siunitx}
\newcommand\perc[1]{\qty[round-mode = places, round-precision = 1,
                        exponent-mode = fixed, fixed-exponent = 0]{#1e2}{\percent}}

\begin{document}
\perc{0.3}
\perc{0.045}
\perc{0}
\end{document}

For \perc{0.3} and \perc{0.045}, this produces 30.0% and 4.5% as intended. However, it fails for 0: \perc{0} results in 0.0 × 10^2. Is this behavior intended by siunitx? Is there a workaround which would give the desired 0.0% output for 0?

2
  • 1
    Does adding drop-exponent = true solve the problem?
    – Celdor
    Jul 30, 2022 at 18:22
  • I'd use an expression here
    – Joseph Wright
    Jul 30, 2022 at 18:25

1 Answer 1

5

Add drop-exponent=true as post-processing option.

\documentclass{article}
\usepackage{siunitx}
\newcommand\perc[1]{\qty[round-mode = places,
                            round-precision = 1,
                            exponent-mode = fixed,
                            fixed-exponent = 0,
                            drop-exponent=true
                        ]{#1e2}{\percent}}

\begin{document}
    \perc{0.3}
    
    \perc{0.045}
    
    \perc{0}
\end{document}

a

0

You must log in to answer this question.

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