Unfortunately, in some of our documents we need to print both SI units as well as Imperial units. We have some macros defined as follows:
\documentclass{article}
\usepackage{fp}
\def\GPM#1{#1 gpm\FPmul\temp{#1}{3.785}
\FPround\temp{\temp}{2}(\temp\ lpm) }
\def\GALLONS#1{#1 gallons \FPmul\temp{#1}{3.785}
\FPround\temp{\temp}{2}(\temp\ litres)}
\def\LPM#1{#1 lpm\FPdiv\temp{#1}{3.785}
\FPround\temp{\temp}{2}(\temp\ gpm)}
\begin{document}
\noindent
\GALLONS{200.00}\\
\GPM{500.00}\\
\LPM{1892.50}
\end{document}

How can one modify the macros, so that if you type a number, the conversion macro picks up the number of decimals automatically and sets the conversion accuracy to the same number of decimals, i.e., typing \GALLONS{150.000} should typeset 567.750 litres.

siunitxfor the units. I can also be used for the rounding. The number of fractional digits can be counted by an recursive macro which reads each a digit a time and increments an counter. – Martin Scharrer♦ Feb 11 '11 at 18:47xstringpackage to detect the accuracy. – Leo Liu Feb 11 '11 at 19:05