James DeVain writes:
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


_______________________________________________
pmwiki-users mailing list
pmwiki-users@pmichaud.com
http://www.pmichaud.com/mailman/listinfo/pmwiki-users

Reply via email to