The fp
package provides neither floor nor ceiling functions. There are round
and trunc
(and clip
that removes trailing zeros). It's quite puzzling that these functions have not been implemented, actually.
Anyway, the official syntax for round
and trunc
is not with a comma:
round(3.14159:2)
would return 3.14
. But it turns out that commas can be used as well.
Implementing floor and ceiling in fp
should not be that hard, but there's something better available, which has the functions.
With no package at all, provided your LaTeX is not more than a couple of years old, you can do
\fpeval{ceil(\first/\second,2)}
and get 6.5
. This is fully expandable, so it can be used even in something like
\fpeval{ceil(\first/\second,2)}\mylen
where \mylen
is some length parameter defined with \newlength
. Thus you shouldn't need to store the result in macros.
You can do it, of course, but I'd not perpetuate the bad practice of not checking about definedness of the commands we want to use.
\documentclass{article}
\ExplSyntaxOn
\NewDocumentCommand{\definefp}{m}
{
\clist_map_inline:nn { #1 }
{
\fp_new:c { l_nvrain_fp_##1_fp }
}
}
\NewDocumentCommand{\setfp}{mm}
{
\fp_set:cn { l_nvrain_fp_#1_fp } { #2 }
}
\NewExpandableDocumentCommand{\usefp}{m}
{
\fp_use:c { l_nvrain_fp_#1_fp }
}
\ExplSyntaxOff
\definefp{raw,result}
\begin{document}
\newcommand{\first}{78}
\newcommand{\second}{11}% to make the thing more interesting
\setfp{raw}{\first/\second}
\setfp{result}{ceil(\first/\second,2)}
Raw: \usefp{raw}
Result: \usefp{result}
\end{document}
This way, you're sure that you don't clobber existing commands, which can very well happen with \FPeval
that never checks about the name of the command it will store the result in.
You can employ \usefp
in any place where a floating point number is expected, even in the second argument to \setfp
or, in general, in the argument of \fpeval
.

lualatex
, and that thegraphicx
has nothing to do with it.