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:

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

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

search

Front-end development

Database

development tools

Open Platform

Javascript development

.NET development

cloud computing

server

Copyright (C) avrocks.com, All Rights Reserved.

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