1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Bug in function?

Discussion in 'Support' started by wbiebel, Aug 11, 2008.

  1. wbiebel

    Joined:
    Jun 28, 2008
    Messages:
    22
    Likes Received:
    0
    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
     
  2. Charles Dye

    Charles Dye Super Moderator
    Staff Member

    Joined:
    May 20, 2008
    Messages:
    3,312
    Likes Received:
    39
    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. wbiebel

    Joined:
    Jun 28, 2008
    Messages:
    22
    Likes Received:
    0
    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
     
  4. Charles Dye

    Charles Dye Super Moderator
    Staff Member

    Joined:
    May 20, 2008
    Messages:
    3,312
    Likes Received:
    39
    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."
     

Share This Page