4

I would like to have a command which executes a simple division of numbers. This \newcommand{\mylen}[1]{1.0 / #1} just prints 1.0 / 3 when invoked as \mylen{3} and not the desired 0.33333. What do I have to do?

Edit: The result should be usable in an expression like \includegraphics[width=\mylen{3}\textwidth]{a}

Danvil
  • 185

1 Answers1

5

If you want this for lengths then it is easy,

\the\dimexpr 1pt/3\relax

produces 0.33333pt. If you don't want the explicit units then the simplest way is to first add pt then remove it from the result.

Or there are several packages that do more exact floating point arithmetic, notably pgf or fp or l3fp

David Carlisle
  • 757,742