plugins/mklauber/math.js does not work completely in TW 5.1.21 ?!?

81 views
Skip to first unread message

Surya

unread,
Oct 10, 2019, 11:33:43 AM10/10/19
to TiddlyWiki
Hello,

The "Calc"-Plugin from https://mklauber.github.io/tiddly-mathjs/ does work only half on my wiki and also on a freshly downloaded wiki. Both Version 5.1.21.
It calculates correctly with simple numbers like <$calc>round({{!!amount}} /2* 2)</$calc>.
But not with numbers like 0.5. For example, if I write <$calc>round({{!!amount}} /4* 1.5)</$calc> (amount-field has "4"), then the result should be 1.5. But the result is 2.
I tried it also with <$calc>round({{!!amount}} /4* 1,5) and with <$calc>round({{!!amount}} /4* 1/2) and <$calc>round({{!!amount}} /4* 1 /2). But nothing helped.

I do not think, that the problem is in my wiki, because it is the same behaviour in a freshly downloaded and totally empty TW (same version).
In another wiki of mine with an older version (5.1.14) it works completely- also with numbers like 1.5.

How to solve that problem??
Thanks for your help!
Surya

Mark S.

unread,
Oct 10, 2019, 12:39:09 PM10/10/19
to TiddlyWiki
4/4 * 1.5 = 1.5, which when rounded is 2. Or at least that's what I get from a quick review of rounding rules.

Birthe C

unread,
Oct 10, 2019, 12:41:28 PM10/10/19
to TiddlyWiki
I think it might have to do with the recent changes in TW5 https://tiddlywiki.com/#Mathematics%20Operators

Birthe

Mark S.

unread,
Oct 10, 2019, 1:32:11 PM10/10/19
to TiddlyWiki
Actually, when I try your sample calculation on mklauber's site,

<$calc>round({{!!amount}}/4 * 1.5)</$calc>

I also get "2".

That site still uses 5.1.9

So maybe you should double-check that the field "amount" contains the value you think it does. I suppose its possible that TW 5.1.14 introduced an error
that was corrected later.

Perhaps export and post the tiddler that is causing the problems, so we can review the actual numbers.

Good luck!

On Thursday, October 10, 2019 at 8:33:43 AM UTC-7, Surya wrote:

Mark S.

unread,
Oct 10, 2019, 1:38:47 PM10/10/19
to TiddlyWiki

Here's a screen shot to show what I mean.

Surya

unread,
Oct 10, 2019, 2:37:27 PM10/10/19
to TiddlyWiki
Hello,
here is one example of 21 recipes in my other wiki with version 5.1.14. They are all working correctly and all these 21 recipes I have a lot of numbers like 0.2, 1.7, and so on. In all of them the amount is correct. I am using these recipes regularly. I would notice it really fast, if there would be a mistake.

Screenshot (20191010-201216).jpg


I tried now in my new wiki with the https://tiddlywiki.com/#Mathematics%20Operators.
I wrote {{{ [[0.5]multiply[1]] }}} > that works correctly (result 0.5).
Also {{{ [[0.5]divide[0.5]multiply[1]] }}} works correctly (result 1).
But I have two problems with it:
1. I cannot find out, how to include my field "amount". So that, when the amount is 0.5 {{{ [[amount]divide[0.5]multiply[1]] }}} gives also 1 as the result.
2. The results are displayed as links- I do not want them as links, but just normal displayed.

How to solve that?
Surya

Mark S.

unread,
Oct 10, 2019, 2:56:33 PM10/10/19
to TiddlyWiki

Notice that in your calculations for rounding, you have the decimal specified at two places:

round(numbers....numbers,2)

If you use that, then round(amount/4 * 1.5,2) = 1.5 (where amount == 4)


For your sample problem with the new math tools, you could say:

<$text text={{{ [{!!amount}divide[0.5]multiply[1]] }}} />

The <$text.../> widget makes it come out as text. Yes, it would be useful if there was a filter operator that would make the result not be a link.

Hmm. You could put a style on the page so that the links no longer looked like links.

HTH!

Surya

unread,
Oct 10, 2019, 3:36:59 PM10/10/19
to TiddlyWiki
That's it :-)))
Thank you!
No, it is okay like this, I can write it like this and do not need an extra style for it.
Yes, you're right with the rounding. But in this wiki I think, I do not need to round. But I am not sure yet... How could I round with 2? (I tried, but successless).

Surya

unread,
Oct 11, 2019, 5:57:54 PM10/11/19
to tiddl...@googlegroups.com
Hello,

I asked my question in a wrong way ("how to round with 2"). In the "calc"-Plugin I had to write "round     ,2", if I wanted that 1.666667 is shown up as 1.67.
I found out now, how I can do that with the maths operators (fixed operator). But unfortunately that gives me also a simple result-number like "4" shown up as 4.00.
In the "calc"-Plugin that was better. When the result was "4", it was displayed as "4". And when the result was "4.6667", it displayed as "4.67" ( if I wrote round ,2).
How could I reach that with the maths operator?

Surya

Surya

unread,
Oct 11, 2019, 6:00:07 PM10/11/19
to TiddlyWiki
Forgot to write...
I saw now, that sometimes I however need that function.
Reply all
Reply to author
Forward
0 new messages