# How to extract the currency symbol?

Within the Datatool package, we find the currency data type.

A currency data type is a currency symbol followed by an integer or real number.

How can I extract the currency symbol out of a currency data ??

\documentclass{article}

\usepackage{datatool}

\newcommand{\splitCurrency}[1]{%
\noindent Splitting #1 into its value and symbol parts:
\DTLifcurrency{#1}% Check: Is #1 currency?
{% Check: #1 is currency !
\\The value: \DTLconverttodecimal{#1}{\theValue} \theValue%
\\The symbol: ??
}{% Check: #1 is not currency !
Not a currency !
}%
}

\begin{document}


\end{document}


• Anyway to force the extension within \getcurrencysymbol, so that I don't have to repeat \expandafter\theCurrency\relax on each use? – Joseph Marie Aug 16 at 10:52
• @JosephMarie I do not understand your question. Why would you have to repeat \expandafter\theCurrency\relax? \expandafter\theCurrency\relax would try to expand the non-expandable \relax, so \expandafter is useless here. – Marcel Krüger Aug 16 at 11:05
• When I run \getcurrencysymbol{\$123}{\symbol}% \DTLnewdbentry{data}{Symbol}{\symbol}%, I get an Error (Extra \else....). When I do \DTLnewdbentry{data}{Symbol}{\expandafter\symbol\relax}%, there is no error. – Joseph Marie Aug 16 at 12:18 • @JosephMarie that's imho a bug in datatool, it fails if the value starts with something that could be a currency. Your \expandafter command hides this. You could also use {\relax\symbol}. I wrote Nicola a mail. – Ulrike Fischer Aug 16 at 14:28 \documentclass{article} \usepackage{datatool} \DTLnewcurrencysymbol{€} \def\splitCurrency#1{\noindent Splitting #1 into its value and symbol parts: \splitCurrencyA#1;} \def\splitCurrencyA#1#2;{% \DTLifcurrency{#1#2}% Check: Is #1 currency? {% Check: #1 is currency ! \\The value: \DTLconverttodecimal{#2}{\theValue} \theValue% \\The symbol: #1 }{% Check: #1 is not currency ! Not a currency ! }% } \begin{document} \splitCurrency{\$123}%

\splitCurrency{€123}%
\end{document}


• Very elegant solution! How does the argument parsing system knowns that he has to split into "text-value" at \def\splitCurrencyA#1#2; ? – Joseph Marie Aug 16 at 10:15
• The currency symbol is only one character or a macro (#1) and the rest until the ; will be the value (#2), that‘s all. – Herbert Aug 16 at 11:36