%%
%% This is file `xprintlen.sty',
%% part of the package xprintlen.
%%
%% Copyright (C) 2014 by Liam Huang <liamhuang0205+xprintlen@gmail.com>
%% --------------------------------------------------------------------------
%% This work may be distributed and/or modified under the
%% conditions of the LaTeX Project Public License, either version 1.3
%% of this license or (at your option) any later version.
%% The latest version of this license is in
%%   http://www.latex-project.org/lppl.txt
%% and version 1.3 or later is part of all distributions of LaTeX
%% version 2005/12/01 or later.
%%
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{xprintlen}[2014/12/25 v1.0 print lengths with units]
\RequirePackage{fp}
\newlength{\CMarg}
\newlength{\CMunit}
\newcommand{\CMspace}{\,}
\newcommand{\defaultunit}{mm}
\newcommand{\defaultsignificant}{2}
\newcommand*{\printlen}[1][\defaultsignificant]{%
  \providecommand{\printlenFirstParameter}{}%
  \renewcommand{\printlenFirstParameter}{#1}%
  \printlenCalculate%
}
\newcommand*{\printlenCalculate}[2][\defaultunit]{%
  \setlength{\CMunit}{1#1}%
  \setlength{\CMarg}{#2}%
  \FPdiv\CMres{\strip@pt\CMarg}{\strip@pt\CMunit}%
  \FPround\CMres\CMres{\printlenFirstParameter}%
  \CMres\CMspace\texttt{#1}%
}