Skip to main content
2 of 3
added 27 characters in body
Mico
  • 556.7k
  • 57
  • 760
  • 1.3k

For the sake of variety, a LuaLaTeX-based solution.

Two remarks about this solution:

  • The default precision displayed by \myPerCent is 3 significant digits. This can be overridden by specifying an optional argument, enclosed in square brackets.

  • The two mandatory arguments of \myPerCent don't have to be numbers. All that's required is that they evaluate to numbers using standard math syntax rules.

enter image description here

% !TEX TS-program = lualatex
\documentclass{article}
\usepackage{luacode} % for '\luaexec' macro
\newcommand{\myPerCent}[3][3]{\luaexec{%
   tex.sprint( 100 * string.format("\%.#1g",(#2)/(#3)) )
   }\,\%}
   
\begin{document}
\myPerCent{2441}{8667}, \myPerCent[5]{2441}{8667}.

\myPerCent{10/2}{2*3},  \myPerCent[5]{10/2}{2*3}.
\end{document}
Mico
  • 556.7k
  • 57
  • 760
  • 1.3k