How to understand if we have number in the field or not

87 views
Skip to first unread message

Siniy-Kit

unread,
Jul 12, 2021, 7:27:37 AM7/12/21
to TiddlyWiki
Hi!  I use minall[]  in filter,  and sometimes get "infinity" when one of the field values is text (not number) How can I check numbers in filter?  (something like is[number]  )

Eric Shulman

unread,
Jul 12, 2021, 10:29:13 AM7/12/21
to TiddlyWiki
On Monday, July 12, 2021 at 4:27:37 AM UTC-7 Siniy-Kit wrote:
Hi!  I use minall[]  in filter,  and sometimes get "infinity" when one of the field values is text (not number) How can I check numbers in filter?  (something like is[number]  )

At present, there is no "is[number]" filter.
However, using a bit of clever math, it is possible to determine if a value is a number:

If you multiply a field value by 1, and get the same value back, then it is a number.   Here are some examples:
<$vars value="5"><<value>> is {{{ [<value>multiply[1]match<value>then[a number]else[not a number]] }}}<br>
<$vars value="0"><<value>> is {{{ [<value>multiply[1]match<value>then[a number]else[not a number]] }}}<br>
<$vars value="foo"><<value>> is {{{ [<value>multiply[1]match<value>then[a number]else[not a number]] }}}<br>

Note that using the match<value> test doesn't properly handle values with leading or trailing zeros (e.g., "5.00" or "005"
<$vars value="5.00"><<value>> is {{{ [<value>multiply[1]match<value>then[a number]else[not a number]] }}}<br>
<$vars value="005"><<value>> is {{{ [<value>multiply[1]match<value>then[a number]else[not a number]] }}}<br>
<$vars value="000"><<value>> is {{{ [<value>multiply[1]match<value>then[a number]else[not a number]] }}}<br>

A more accurate test would be to use compare:number:eq<value>
<$vars value="5.00"><<value>> is {{{ [<value>multiply[1]compare:number:eq<value>then[a number]else[not a number]] }}}<br>
<$vars value="005"><<value>> is {{{ [<value>multiply[1]compare:number:eq<value>then[a number]else[not a number]] }}}<br>
<$vars value="000"><<value>> is {{{ [<value>multiply[1]compare:number:eq<value>then[a number]else[not a number]] }}}<br>

enjoy,
-e

trend

unread,
Jul 12, 2021, 10:30:40 AM7/12/21
to tiddl...@googlegroups.com
Hi,

I'm not sure if it will work for you. But you could try something with the "compare Operator". It has a type for numbers and integers.
And perhaps combined with "Conditional Operators".


Kind regards,
Trend.


On Monday, 12 July 2021 13:27:37 (+02:00), Siniy-Kit wrote:

Hi!  I use minall[]  in filter,  and sometimes get "infinity" when one of the field values is text (not number) How can I check numbers in filter?  (something like is[number]  )

--
You received this message because you are subscribed to the Google Groups "TiddlyWiki" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tiddlywiki+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/tiddlywiki/75155f75-3c13-409f-ace8-2799d5d9a7ban%40googlegroups.com.

-- 

Jeremy Ruston

unread,
Jul 12, 2021, 10:48:16 AM7/12/21
to tiddl...@googlegroups.com
Hi Siniy-Kit,

Hi!  I use minall[]  in filter,  and sometimes get "infinity" when one of the field values is text (not number) How can I check numbers in filter?  (something like is[number]  )

That seems like a bug with the minall[] operator. All the numeric operators are supposed to treat items that can’t be parsed as a number as zero. Thus the following filter returns zero:

1 2 3 chicken +[minall[]]

Can you give an example of the values that return Infinity?

Many thanks,

Jeremy

Siniy-Kit

unread,
Jul 12, 2021, 11:18:33 AM7/12/21
to TiddlyWiki
Hi, Jeremy. You are write and in  1 2 3 chicken +[minall[]] we get 0 ( I want to get 1....)

infinity I see here

when  I try this filter  {{{[is[current]tagging[]tag[$:/Note]!tag[$:/TOC]!ostatok[0]get[price]minall[]]}}}



понедельник, 12 июля 2021 г. в 17:48:16 UTC+3, jeremy...@gmail.com:

Siniy-Kit

unread,
Jul 12, 2021, 11:21:56 AM7/12/21
to TiddlyWiki
I understand the problem was in  !ostatok[0]  my filter was empty

понедельник, 12 июля 2021 г. в 17:48:16 UTC+3, jeremy...@gmail.com:
Hi Siniy-Kit,

Jeremy Ruston

unread,
Jul 12, 2021, 11:29:24 AM7/12/21
to tiddl...@googlegroups.com
Hi Siniy-Kit,

That’s correct: minall[] applied to an empty input list will return the special value “Infinity”.

You should be able to fix things with an “else” run:

 {{{[is[current]tagging[]tag[$:/Note]!tag[$:/TOC]!ostatok[0]get[price]] ~0 +[minall[]]}}}

Best wishes

Jeremy

Siniy-Kit

unread,
Jul 12, 2021, 11:29:44 AM7/12/21
to TiddlyWiki
OK. How can I get 0 (not infinity) in this filter {{{[tag[notag]get[price]minall[]]}}} when there is no tiddlers with tag  "notag"

понедельник, 12 июля 2021 г. в 17:48:16 UTC+3, jeremy...@gmail.com:
Hi Siniy-Kit,

Jeremy Ruston

unread,
Jul 12, 2021, 11:31:15 AM7/12/21
to tiddl...@googlegroups.com
Try:

{{{ [tag[notag]get[price]] ~0 +[minall[]] }}}

Best wishes

Jeremy

Siniy-Kit

unread,
Jul 12, 2021, 11:33:57 AM7/12/21
to TiddlyWiki
Thank you Jeremy. It works good. And where I can read about this "~" symbol in filters. I never use it.   

понедельник, 12 июля 2021 г. в 18:31:15 UTC+3, jeremy...@gmail.com:

Jeremy Ruston

unread,
Jul 12, 2021, 11:36:33 AM7/12/21
to tiddl...@googlegroups.com
The ~ symbol at the start of a run is a synonym for “:else”, and it means that the run will only be processed if the current list is empty. There are some docs here:


Best wishes

Jeremy

TW Tones

unread,
Jul 13, 2021, 6:35:21 PM7/13/21
to TiddlyWiki
Siniy-Kit,

To stop non numbers existing in a field to begin with, you may want to make use of the html type on the edit-text widget.

<$edit-text tiddler=test field=my-number type=number/>

Also;
  • Other enhancements to the edit-text widget may allow you to test or control the values entered
  • You may be interested in this discussion which shows how you can increment numbers that have units attached.
I believe we could build on the Mathematics operators documentation, for example can we say match[Infinity] or match[!Infinity]


Regards
Tones
Reply all
Reply to author
Forward
0 new messages