[pmwiki-users] Problem with MarkupExpression {(calc)} recipe
James DeVain
jamesdevain at mail.com
Tue Jan 7 20:07:29 CST 2014
> Hi, folks. I'm having a problem with the {(calc )} recipe on the page
> Cookbook/MarkupExpressionSamples. For example, {(calc 100 + 10)} displays the
> correct answer, but {(calc 100 + 010)} shows 108 for some reason. I need be
> able to include the seemingly useless preceeding "0" because sometimes I'm
> referring a PTV that may not exist, like:
>
> {(calc {$:num_a} + 0{$:num_b})}
>
> but there is no value set for num_b, so the 0 prevents an input error.
>> Oh, you don't want that.
>>
>> In PHP numbers starting with 0 are considered to be "octal", base 8 not base
>> 10, and 010 (octal) is indeed 8 (decimal). If such a number contains 8 or 9,
>> it is trimmed before them so 018 becomes 01 (octal), that is 1 (decimal).
>>
>> How about use {$:num_b}.0 or ({$:num_b}-0) ? Note that you should quote your
>> entire expression as parentheses mean sub-expressions:
>>
>> {(calc '{$:num_a} + ( {$:num_b} - 0 )')} note the apostrophes
>>
>> Petko
Thanks so much, Petko. I had no idea about the octal numbers. I can't use
{$:num_b}.0 because some of the numbers will already have a decimal, but
the {$:num_b}-0 idea solves my problem completely.
I really appreciate it.
More information about the pmwiki-users
mailing list