# How to get float numbers as parameter of \newcommand

I have defined a \newcommand function like into this code:



I would like to be able to call the command with both real or integer numbers:

\subexo{Anything}{2} 


or

\subexo{Something}{0.5} 


But I have errors like this with my current code:

! Package calc Error: .' invalid at this point.


What should I modify into my \newcommand definition to do this ?

Replay

Counters can only contain integer numbers. If you want to deal with real numbers you have to play with lengths.

The following MWE uses lengths instead of counters (the internal macro \[email protected] is used to strip pt when printing the length):

\documentclass{scrartcl}
\usepackage{pbox,calc}

\makeatletter
\newcommand*{\strippt}[1]{\[email protected]#1}
\makeatother

\newlength{\pointsExo}
\setlength{\pointsExo}{4pt}
\newlength{\pointsSousTotal}
\setlength{\pointsSousTotal}{0pt}

\newlength{\souspointsExo}
\newcommand{\sousPoints}[1]{
\setlength{\souspointsExo}{#1pt}
\setlength{\pointsSousTotal}{\pointsSousTotal + #1pt}
{\scriptsize{(#1~\ifdim#1pt=1pt point\else points\fi/\strippt\pointsExo)}}
}

\newcommand{\subexo}[2]{
#1\hfill\sousPoints{#2}% Points
\medskip
}
\begin{document}
\subexo{Anything}{2}

\subexo{Something}{0.5}
\end{document}

`

Output:

Category: macros Time: 2014-04-15 Views: 0