How to pass in a ratio in fractional form?

How to pass in a ratio of 4/15 (instead of its approximated decimal form of 0.266) to table definition.

Final solution can be seen here.

I need one more vote to close this topic.

-
But, if you have another solution, welcome! – xport Dec 26 '10 at 18:52
Unfortunately, the \ratio above cannot accept dimensionless values such as \ratio{4}{15}. :-( – xport Dec 26 '10 at 19:30
If you want some overkill, you could use pgfmathparse. – Caramdir Dec 26 '10 at 19:33
@Caramdir, I will revisit this tomorrow. Thank you for commenting. – xport Dec 26 '10 at 19:44
@xport: Only the first comment in your \ratio macro is necessary. – TH. Dec 28 '10 at 9:11

If you want more accurate calculations use the fp package.

For example using the fp package as shown below you get 0.999999999999999998 rather than 0.998.

\documentclass[11pt]{article}
\usepackage{fp}
\begin{document}
\parindent0pt
\FPdiv\paramtwo{4}{15}
\FPdiv\paramthree{2}{15}
\FPmul\paramtemp{4}{\paramthree}
\FPdiv\paramseven{3}{15}

\total
\end{document}


No need for any manual calculations!

You can use it in a tabular as follows (remember it creates variable names on the fly)

\documentclass[11pt]{article}
\usepackage{fp}

\FPdiv\columni{3.9999999}{3.8888888}
\FPdiv\columnii{1.11123456}{1.3999999}

\begin{document}

\begin{tabular}{|p{\columni cm}|p{\columnii cm}|}
a & b \\
c & d \\
\end{tabular}


\end{document}

-
@Yiannis, thanks for answering. It is useful. – xport Dec 27 '10 at 1:41
@xport \def\division#1#2{ \FPdiv\result{#1}{#2} \result } \division{2}{9999} – Yiannis Lazarides Dec 27 '10 at 3:51
@Yiannis, please kindly see again my last update above. – xport Dec 27 '10 at 5:05
@xport: I didn't check for sure, but the problem is that the \FP macros are not expandable. You're going to have to do the division before you need to use the result in an expandable manner. – TH. Dec 27 '10 at 12:02

I cannot see a gap with a zoom of 400% ...

\documentclass{article}
\parindent=0pt
\textwidth=15cm
\begin{document}

\rule{\textwidth}{5mm}

\rule{0.2667\textwidth}{5mm}%
\rule{0.1333\textwidth}{5mm}%
\rule{0.1333\textwidth}{5mm}%
\rule{0.1333\textwidth}{5mm}%
\rule{0.1333\textwidth}{5mm}%
\rule{0.2\textwidth}{5mm}

\end{document}

-
because you took more accurate decimal numbers. You lost only 0.0001 in total. :-) – xport Dec 26 '10 at 19:00
even though there is no gap by taking more accurate decimal ratios, doing conversion manually is tedious. – xport Dec 26 '10 at 19:09
-