Note from xint
package developer:
The documentation is not clear enough that \xintDecSplitR
is an integer only macro (in fact it is mainly used internally, but some forgotten reason I gave it a public interface). Thus the spurious dot is an after-effect from using the macro on unexpected input. It could have been spurious !
or spurious ;
if I had coded it otherwise internally. By luck the dot indeed can be removed by \xintNum
.
I thus recommend rather egreg's approach, because this one works for accidental reasons. xint
implemented decimal numbers at the same time as fractions and is lacking utilities which makes perfect sense for fixed point numbers only. Thus there is no high level one-shot interface to what is asked here.
Here's a way to do it with xint
:
\documentclass{article}
\usepackage{xintexpr}
\def\x{59.3612}
\newcommand{\getint}[1]{\xintNum{#1}\relax}
\newcommand{\getdec}[1]{\xintNum{\xintDecSplitR{0}{#1}}\relax}
\begin{document}
The integer part: \xintNum{\x}\relax % Or just \getint{\x}
The decimal part: \xintNum{\xintDecSplitR{0}{\x}}\relax % Or just \getdec{\x}
\end{document}

From what I can tell from the package documentation:
\xintNum{x}
truncates the fractional number x
and returns an integer value.
\xintDecSplit{n}{x}
cuts the number x
into two pieces and returns two floats. If n
is 0, then the split is performed at the decimal point. The corresponding command \xintDecSplitR{n}{x}
returns the number on the right side after cutting, in this case, the decimal portion of x
. I've had to wrap it in its own \xintNum
to convert the float into an integer, so you don't get a spurious dot at the end.
Finally, it's possible to wrap the entire expression in your own custom commands, like I did with \getint
and \getdec
so it doesn't get messy in your main code.