# [Pmwiki-users] Re: calculating directives ?

J. Meijer commentgg
Fri Jun 18 19:20:38 CDT 2004

```Knut, I did not adapt the syntax. My code does this markup:

?formula?           prints result of formula (and stores it in ?\$?)
?formula=\$var?  prints the *formula* and stores result in \$var
?\$var?              prints \$var

It allows you to do something like:

Contributions total (?11.10 * 10=\$?) = M\$?\$?
Contributions total M\$?11.10 * 10?

and have it printed as:

Contributions total (11.10 * 10) = M\$111.00
Contributions total M\$111.00

Most math functions are supported, including the very useful round(). Any

However it does not do this, I didn't get to this:

You know ?1=\$a?+?1=\$b? is ?\$a+\$b?
to print as
You know 1+1 is 2

Which is obviously the kind of app you want.
Goodluck,

-jm

# inline calculations with var storage:
#   ?formula? ?formula=\$var? and ?\$var?
'sqrt|pi|log|log10|exp|pow|hexdec|dechex|round|rand|';
\$evalfulist="((?:".str_replace('|','\\(|',\$evalfulist).
'&amp;|&gt;|&lt;|[0-9.eE+-\\/*%|~\\(\\) ])+?)';
\$DoubleBrackets['/?'.\$evalfulist.'(=\\\$([a-z]*))??/e']=
"eval('\\$gfr\$3='.html_entity_decode('\$1').
';return (\'\$2\')?\'\$1\':\\$gfr;')";
\$DoubleBrackets['/?\\\$([a-z]*)?/e']= '\$gfr\$1';

---- Original Message ----

> Knut, I published some formula-evaluation code before using a
> ((..)) syntax. I made a revision since then to use variables, I'll
> Probably.
>
> -jm
>
>
> [[calc \$var=expression]] to set a variable without displaying the
> result [[show \$var=expression]] to set the variable and displaying
> the result in the wikitext
> [[show expression]] incl [[show \$var]] to show the result in the
> wiki-text
>
> I thought of evaluating php-functions for the expressions and
> assignments maybe added by some user-written php-functions

```