Suppose, I have a floating point value inside expl3 block. Can I use it's decimal representation outside of expl3 block?

This doesn't work:


\fp_new:N  \val
\fp_set:Nn \val{6.5}

\fp_set:Nn \val \fp_to_decimal:N \val

1 Answer 1


The line

\fp_set:Nn \val \fp_to_decimal:N \val

is wrong code. If we remove it and ask TeX \show\val, we get

> \val=macro:
->\s__fp \__fp_chk:w 10{1}{6500}{0000}{0000}{0000};.

which tells us that \val cannot probably be used by itself in a document, because in some sense it contains an abstract representation of the floating point variable. You have to say

\fp_use:N \val

in order to deliver in the input stream the representation of the floating point value. Saying \fp_to_decimal:N \val is the same, as explained in the documentation.

There is no official document interface for floating point variables, at the moment, so you have to define your own. For instance

\NewDocumentCommand{\newfpvar}{m}{\fp_new:N #1}
\NewDocumentCommand{\setfpvar}{mm}{\fp_set:Nn #1 { #2 }}
\NewDocumentCommand{\getfpvar}{m}{\fp_use:N #1}

so you can say

\setfpvar{\val}{6.5+3.01} % any floating point expression

Don't forget to add \usepackage{xparse} to your preamble.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .