# Use expl3 variable decimal representation outside of expl3 block

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:

\documentclass{article}
\usepackage{expl3}
\begin{document}
\ExplSyntaxOn

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

\fp_set:Nn \val \fp_to_decimal:N \val
\ExplSyntaxOff
\val
\end{document}


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

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


so you can say

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


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