Bug in function?

#1
Watch this:

C:\Programme\TCMD
> function currency=`%@comma[%@formatn[-70.2,%1]]`

C:\Programme\TCMD
> echo %@currency[741,31]
741,00

C:\Programme\TCMD
> echo %@comma[%@formatn[-70.2,741,31]]
741,31

How can this be?
Greetings WB
 

Charles Dye

Super Moderator
Staff member
May 20, 2008
3,575
46
Albuquerque, NM
prospero.unm.edu
#2
Watch this:

C:\Programme\TCMD
> function currency=`%@comma[%@formatn[-70.2,%1]]`

C:\Programme\TCMD
> echo %@currency[741,31]
741,00

C:\Programme\TCMD
> echo %@comma[%@formatn[-70.2,741,31]]
741,31

How can this be?
Greetings WB
In the first example, the first comma is a parameter separator. It separates the first argument to your function (741, which becomes %1) from the second (31, which becomes %2 and is duly ignored.)

In the second example, @FORMATN is expecting only two arguments. The second comma therefore can't be a parameter separator -- it's a thousands separator (and is ignored.) Your second argument is simply 74131 -- or 74,131 if you insert thousands separators.
 
#3
In the first example, the first comma is a parameter separator. It separates the first argument to your function (741, which becomes %1) from the second (31, which becomes %2 and is duly ignored.)

In the second example, @FORMATN is expecting only two arguments. The second comma therefore can't be a parameter separator -- it's a thousands separator (and is ignored.) Your second argument is simply 74131 -- or 74,131 if you insert thousands separators.
Sorry, but this is wrong. I have the german settings. Watch this:

C:\Programme\TCMD
> function currency=`%@comma[%@formatn[-70.2,%1]]`

C:\Programme\TCMD
> echo %@currency[13741,31]
13.741,00

C:\Programme\TCMD
> echo %@comma[%@formatn[-70.2,13741,31]]
13.741,31

The thousands separators are set correctly and the @formatn also correctly recognizes the comma. The next lines show this:

C:\Programme\TCMD
> echo %@formatn[-70.2,13741,31]
13741,31

C:\Programme\TCMD
> echo %@comma[13741,31]
13.741,31

Everything is fine -- but not as a function.
Greetings WB
 

Charles Dye

Super Moderator
Staff member
May 20, 2008
3,575
46
Albuquerque, NM
prospero.unm.edu
#4
Sorry, but this is wrong. I have the german settings. Watch this:

C:\Programme\TCMD
> function currency=`%@comma[%@formatn[-70.2,%1]]`

C:\Programme\TCMD
> echo %@currency[13741,31]
13.741,00

C:\Programme\TCMD
> echo %@comma[%@formatn[-70.2,13741,31]]
13.741,31

The thousands separators are set correctly and the @formatn also correctly recognizes the comma. The next lines show this:

C:\Programme\TCMD
> echo %@formatn[-70.2,13741,31]
13741,31

C:\Programme\TCMD
> echo %@comma[13741,31]
13.741,31

Everything is fine -- but not as a function.
Greetings WB
Okay, the comma is your decimal separator, not your thousands separator; got it. But the issue is still the same: that comma is being interpreted as a parameter separator, not as a part of the number. Try this to see what's happening:

Code:
function currency=`%%1 is %1 - %%2 is %2 - %%3 is %3`
echo %@currency[13741,31]
You don't want your function argument chopped up in this fashion, so I suggest that you use %$ instead of %1:

Code:
function currency=`%@comma[%@formatn[-70.2,%$]]`
echo %@currency[13741,31]
Note to Rex: In the help for FUNCTION, the section covering %$ and %n$ appears to have been copied verbatim from the alias documentation. Could use some editing, e.g. "the entire command line" should read "all arguments," and "after the alias names" might say "passed to the function."