calulate with math operators and Variables

112 views
Skip to first unread message

Gerald Weis

unread,
Feb 17, 2020, 2:23:47 PM2/17/20
to TiddlyWiki
I have written an Maro with the follow defininitions

\define Benzkauf2(Datum kmalt kmneu getankt Gesamtpreis)
<tr align=right>
    <td>$Datum$</td>
    <td>$kmalt$</td>
    <td>$kmneu$</td>
    <td>$getankt$</td>
    <td>$Gesamtpreis$</td>
    <td>[[$kmneu$ $kmalt$ substract[]]</td>
    <td>[[$getankt$]multiply[100]divide[[$kmneu$ $kmalt$ substract[]]]</td>
    <td>[[$Gesamtpreis$]divide[$getankt$]]</td>
</tr>
\end

but the caltulating do not work.

It shoud do so

1. kmneu - kmalt
2. getankt * 100 / (kmneu - kmalt)
3. Preisgesamt / getankt

how i can do it

thanks for help


Mat

unread,
Feb 17, 2020, 3:45:05 PM2/17/20
to TiddlyWiki
Looking at the documentation example for subtract

[[$kmneu$ $kmalt$ substract[]]

should probably be

[[$kmneu$]subtract[$kmalt$]]

And you type

 <td>[[$Gesamtpreis$]divide[$getankt$]]</td>

but you state

3. Preisgesamt / getankt

i.e another name for the variable

<:-)

Mat

unread,
Feb 17, 2020, 3:46:43 PM2/17/20
to TiddlyWiki
Note also that thing is calculated just because it's within brackets like that. If you want the expression evaluated it must also be enclosed in triple braces like so:

{{{ [...] }}}

<:-)

Gerald Weis

unread,
Feb 18, 2020, 1:51:15 AM2/18/20
to tiddl...@googlegroups.com
{{
Hello Mat,

i was trying your solutions.
i have read the dokumentation in tiddlywiki.com.

<td>{{{[[$kmneu$]subtract[$kmalt$]]}}}</td>

<td>{{{[[$Gesamtpreis$]divide[$getankt$]]</td>}}}

thats work

thanks

Only this dont work
<td>{{{[[[$getankt$]multiply[100]]divide[$kmneu$ substract[$kmalt$]]}}</td>
Its calculatete the equations, but not the solution of both.

its mean
1. {{{[[[$getankt$]multiply[100]]}}
2. {{{[$kmneu$ substract[$kmalt$]]}}

thats what my equation do
its dont divide

Eric Shulman

unread,
Feb 18, 2020, 3:26:44 AM2/18/20
to TiddlyWiki
On Monday, February 17, 2020 at 10:51:15 PM UTC-8, Gerald Weis wrote:
<td>[[$kmneu$]subtract[$kmalt$]]</td>
<td>[[[$getankt$]multiply[100]]divide[[$kmneu$ $kmalt$ substract[]]]]</td>

<td>[[$Gesamtpreis$]divide[$getankt$]]</td>
 
You are using the wrong kind of outer brackets.

To *evaluate* a filter, use tripled curly braces around the entire filter expression.  Also, you can't "nest" filters, so use a variable to hold the result of the first calculation, and then reference that variable in the second calculation.
Finally, *after* computing the desired values, reference the variables to produce the output.

Thus:

\define Benzkauf2(Datum kmalt kmneu getankt Gesamtpreis)
<$vars v1={{{ [[$kmneu$]subtract[$kmalt$]] }}}>
<$vars v2={{{ [[$getankt$]multiply[100]divide<v1>] }}}>
<$vars v3={{{ [[$Gesamtpreis$]divide[$getankt$]] }}}>

<tr align=right>
   
<td>$Datum$</td>
    <td>$kmalt$</
td>
   
<td>$kmneu$</td>
    <td>$getankt$</
td>
   
<td>$Gesamtpreis$<
/td>
    <td><<v1>></
td>
   
<td><<v2>></td>
   
<td><<v3>></td>
</tr>
</
$vars>
</$vars>
</
$vars>
</tr>
\end

That should do what you want.  Let me know how it goes.

enjoy,
-e
Eric Shulman
TiddlyTools.com: "Small Tools for Big Ideas!" (tm)


Gerald Weis

unread,
Feb 18, 2020, 4:42:04 AM2/18/20
to TiddlyWiki
Hallo Eric,
i have tested it.
Its works fine.

now i have trying to round it on 2 or 3 Digits behind the decimnalpoint.
i dont find it.

thankyou

Eric Shulman

unread,
Feb 18, 2020, 5:52:23 AM2/18/20
to TiddlyWiki
On Tuesday, February 18, 2020 at 1:42:04 AM UTC-8, Gerald Weis wrote:
now i have trying to round it on 2 or 3 Digits behind the decimnalpoint.
i dont find it.

TW Math filters include round[], trunc[], ceil[], and floor[]... any of which can be used to remove the decimal part of a number

To retain given number of decimal places, you would first multiply by a power of 10 (to shift the decimal place to the right), then apply round[] (or any of the other similar filters), and then divide again by the same power of 10 to shift the decimal place back to its original position in the number.  Thus:

<$vars v3={{{ [[$Gesamtpreis$]divide[$getankt$]multiply[1000]round[]divide[1000]] }}}>

will round the number to 3 decimal places.

enjoy,
-e

Gerald Weis

unread,
Feb 18, 2020, 6:15:47 AM2/18/20
to TiddlyWiki
You are top

thanks
Reply all
Reply to author
Forward
0 new messages