# How to print a length accurately and with user-controlled rounding?

Tried the printlen package, but it seems to not understand what 2.5in means:

\documentclass{minimal}
\usepackage{printlen}
\uselengthunit{in}
\begin{document}
\end{document}


Typesetting the above yields 2.50049 in --- is there something better?

NB - in addition to the above, the project in question needs the packages:

\usepackage{calc,geometry,xcolor,graphicx,csvsimple}


the last in particular, conflicts w/ the answers initially provided.

-

\documentclass[preview,border=12pt,varwidth]{standalone}
\usepackage[nomessages]{fp}
\usepackage{printlen}
\makeatletter
\newcommand{\printer}[3][in]{%
\FPeval\temp{round(\expandafter\strip@pt\csname#2\endcsname/72.27:#3)}%
\temp#1}
\makeatother

\newlength\xxx
\setlength{\xxx}{2.5in}
\parindent=0pt

\begin{document}

\printer{xxx}{1}

\printer{xxx}{2}

\printer{xxx}{7}

\end{document}


-

The recently uploaded lengthconvert package seems to be what you're looking for:

\documentclass{article}
\usepackage{lengthconvert}
\Convertsetup{unit=in}
\begin{document}

\Convert{72.27pt}

\end{document}


-
Unfortunately, it clashes with csvsimple --- I've emailed the two package authors, so hopefully this will get worked out. – WillAdams Jul 9 '13 at 16:26
The macro \TrimSpaces in csvsimple should have an @ name, since it's an internal of the package. The clash is with xparse, rather than lengthconvert – egreg Jul 9 '13 at 16:30
Prof. Sturm, the author of csvsimple pointed out in a private e-mail that re-ordering the packages would've been sufficient to fix this, but has indicated that he will change the relevant macro name in his next update. Thanks! – WillAdams Jul 10 '13 at 16:31
@WillAdams No, it wouldn't be sufficient; loading csvsimple after xparse would avoid raising the error in this particular case, but would break xparse. – egreg Jul 10 '13 at 16:33
Okay, next version then. – WillAdams Jul 10 '13 at 16:48

The obligatory expl3 solution:

\documentclass{minimal}
\usepackage{expl3,xparse}
\ExplSyntaxOn
\NewDocumentCommand { \printlengthas } { m m }
{ \dim_to_decimal_in_unit:nn {#1} { 1 #2 } #2 }
\ExplSyntaxOff
\begin{document}

(\dim_to_unit:nn is currently experimental, but the idea is bound to stay: just a question of the name.)
Note: this currently requires a recent release of expl3: \dim_to_decimal_in_unit:nn was added to the CTAN version on 2014-07-15.
I see egreg's solution also uses expl3 internally: mine is a wrapper around basic TeX arithmetic only (lenghtconvert uses the L3 FPU). – Joseph Wright Jul 9 '13 at 15:22
Unfortunately, this doesn't play well w/ csvsimple either. – WillAdams Jul 9 '13 at 16:28
@WillAdams I think that should be asked as a separate question ('How to use csvsimple and xparse: clash over \TrimSpaces'). A solution is I think easy, as csvsimple uses \TrimSpaces only internally and only in one place, and this can be fixed using an alternative version from expl3. (This is separate from the question posed here, so two separate but linked questions would be better than one with two entirely separate parts.) – Joseph Wright Jul 9 '13 at 16:38
dim_to_unit isn't documented :-( – Marco Daniel Jul 9 '13 at 17:05
@WillAdams The fixed version of csvsimple has been uploaded on CTAN (and included in TeX Live) – egreg Sep 27 '13 at 11:09