How to get float numbers as parameter of \newcommand

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

\documentclass{scrartcl} \usepackage{pbox,calc}  \newcounter{pointsExo} \setcounter{pointsExo}{4} \newcounter{pointsSousTotal} \setcounter{pointsSousTotal}{0}  \newcounter{souspointsExo} \newcommand{\sousPoints}[1]{     \setcounter{souspointsExo}{#1}     \setcounter{pointsSousTotal}{\value{pointsSousTotal} + #1}     {\scriptsize{(#1~\ifthenelse{#1<2}{point}{points}}/\arabic{pointsExo})} }  \newcommand{\subexo}[2]{     #1\hfill\sousPoints{#2}% Points     \medskip } \begin{document} \subexo{Anything}{2}  \subexo{Something}{0.5} \end{document} 

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




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 ?


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):


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


    \setlength{\pointsSousTotal}{\pointsSousTotal + #1pt}
    {\scriptsize{(#1~\ifdim#1pt=1pt point\else points\fi/\strippt\pointsExo)}}

    #1\hfill\sousPoints{#2}% Points



How to get float numbers as parameter of \newcommand

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

Related post

iOS development

Android development

Python development

JAVA development

Development language

PHP development

Ruby development


Front-end development


development tools

Open Platform

Javascript development

.NET development

cloud computing


Copyright (C), All Rights Reserved.

processed in 0.147 (s). 12 q(s)