ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
* [NTG-context] max function in spreadsheettable
@ 2024-10-15  8:59 juh+ntg-context--- via ntg-context
  2024-10-15 10:42 ` [NTG-context] " Henning Hraban Ramm
  0 siblings, 1 reply; 11+ messages in thread
From: juh+ntg-context--- via ntg-context @ 2024-10-15  8:59 UTC (permalink / raw)
  To: mailing list for ConTeXt users; +Cc: juh+ntg-context

Dear all,

I have a cell that calculates a value that may not be a negative value. 
If it is a negatiive value the cell should show zero.


\startcell[style=normal]
@ "0.2f EUR" $pauschale.eintag$ - ((D[row] * (0.2  * 
$pauschale.vororttag$)) + (E[row] * (0.4  * $pauschale.vororttag$)) + 
(F[row] * (0.4  * $pauschale.vororttag$)))
\stopcell

The $-variables will get resolved by Pandoc before ConTeXt comes into play.

As far as I understood the handdbook spreadsheets-mkiv.pdf it is 
possible to define lua functions inside a cell.

Who would you implement a max function that sets the value to 0 if it is 
negative?

TIA
juh

P.S. For German speakers: We try to implement a Reisekostenformular.
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / https://mailman.ntg.nl/mailman3/lists/ntg-context.ntg.nl
webpage  : https://www.pragma-ade.nl / https://context.aanhet.net (mirror)
archive  : https://github.com/contextgarden/context
wiki     : https://wiki.contextgarden.net
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [NTG-context] Re: max function in spreadsheettable
  2024-10-15  8:59 [NTG-context] max function in spreadsheettable juh+ntg-context--- via ntg-context
@ 2024-10-15 10:42 ` Henning Hraban Ramm
  2024-10-15 12:33   ` juh+ntg-context--- via ntg-context
  0 siblings, 1 reply; 11+ messages in thread
From: Henning Hraban Ramm @ 2024-10-15 10:42 UTC (permalink / raw)
  To: ntg-context

Am 15.10.24 um 10:59 schrieb juh+ntg-context--- via ntg-context:
> Dear all,
> 
> I have a cell that calculates a value that may not be a negative value. 
> If it is a negatiive value the cell should show zero.
> 
> 
> \startcell[style=normal]
> @ "0.2f EUR" $pauschale.eintag$ - ((D[row] * (0.2  * 
> $pauschale.vororttag$)) + (E[row] * (0.4  * $pauschale.vororttag$)) + 
> (F[row] * (0.4  * $pauschale.vororttag$)))
> \stopcell
> 
> The $-variables will get resolved by Pandoc before ConTeXt comes into play.
> 
> As far as I understood the handdbook spreadsheets-mkiv.pdf it is 
> possible to define lua functions inside a cell.
> 
> Who would you implement a max function that sets the value to 0 if it is 
> negative?

I’d advise against using the spreadsheet module and for CLD, i.e. 
creating the table from the Lua end. How that works from Markdown 
metadata (that I know you’re using) I’m not sure. It might make sense to 
avoid the Pandoc step and read Markdown or whatever input format with Lua.

WRT German: if you setup a decimal comma with the spreadsheet module, 
all dots get replaced by commas, e.g. in abbreviations – one reason to 
avoid that module.

Otherwise it should be possible to define that function in Lua and use 
it in the table.

I guess you know the cld-mkiv manual?

Hraban
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / https://mailman.ntg.nl/mailman3/lists/ntg-context.ntg.nl
webpage  : https://www.pragma-ade.nl / https://context.aanhet.net (mirror)
archive  : https://github.com/contextgarden/context
wiki     : https://wiki.contextgarden.net
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [NTG-context] Re: max function in spreadsheettable
  2024-10-15 10:42 ` [NTG-context] " Henning Hraban Ramm
@ 2024-10-15 12:33   ` juh+ntg-context--- via ntg-context
  2024-10-15 15:16     ` Hans Hagen via ntg-context
  0 siblings, 1 reply; 11+ messages in thread
From: juh+ntg-context--- via ntg-context @ 2024-10-15 12:33 UTC (permalink / raw)
  To: ntg-context; +Cc: juh+ntg-context

Am 15.10.24 um 12:42 schrieb Henning Hraban Ramm:
> I guess you know the cld-mkiv manual?

I know that it is there. ;-)

I'll try to reimplement the document with cld.

First question:

local sum = string.format("%0.2f", (0.3 * 100))

Gives 30.00

how do I get 30,00

juh


___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / https://mailman.ntg.nl/mailman3/lists/ntg-context.ntg.nl
webpage  : https://www.pragma-ade.nl / https://context.aanhet.net (mirror)
archive  : https://github.com/contextgarden/context
wiki     : https://wiki.contextgarden.net
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [NTG-context] Re: max function in spreadsheettable
  2024-10-15 12:33   ` juh+ntg-context--- via ntg-context
@ 2024-10-15 15:16     ` Hans Hagen via ntg-context
  2024-10-15 19:37       ` juh+ntg-context--- via ntg-context
  2024-11-14  7:59       ` [NTG-context] string.formatters (was: Re: max function in spreadsheettable) juh+ntg-context--- via ntg-context
  0 siblings, 2 replies; 11+ messages in thread
From: Hans Hagen via ntg-context @ 2024-10-15 15:16 UTC (permalink / raw)
  To: juh+ntg-context--- via ntg-context; +Cc: Hans Hagen

On 10/15/2024 2:33 PM, juh+ntg-context--- via ntg-context wrote:
> Am 15.10.24 um 12:42 schrieb Henning Hraban Ramm:
>> I guess you know the cld-mkiv manual?
> 
> I know that it is there. ;-)
> 
> I'll try to reimplement the document with cld.
> 
> First question:
> 
> local sum = string.format("%0.2f", (0.3 * 100))
> 
> Gives 30.00
> 
> how do I get 30,00

local sum = string.formatters["%0.2M"](0.3 * 100)

-----------------------------------------------------------------
                                           Hans Hagen | PRAGMA ADE
               Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
        tel: 038 477 53 69 | www.pragma-ade.nl | www.pragma-pod.nl
-----------------------------------------------------------------
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / https://mailman.ntg.nl/mailman3/lists/ntg-context.ntg.nl
webpage  : https://www.pragma-ade.nl / https://context.aanhet.net (mirror)
archive  : https://github.com/contextgarden/context
wiki     : https://wiki.contextgarden.net
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [NTG-context] Re: max function in spreadsheettable
  2024-10-15 15:16     ` Hans Hagen via ntg-context
@ 2024-10-15 19:37       ` juh+ntg-context--- via ntg-context
  2024-10-15 19:58         ` Wolfgang Schuster
  2024-10-15 20:04         ` Henning Hraban Ramm
  2024-11-14  7:59       ` [NTG-context] string.formatters (was: Re: max function in spreadsheettable) juh+ntg-context--- via ntg-context
  1 sibling, 2 replies; 11+ messages in thread
From: juh+ntg-context--- via ntg-context @ 2024-10-15 19:37 UTC (permalink / raw)
  To: ntg-context; +Cc: juh+ntg-context

Am 15.10.24 um 17:16 schrieb Hans Hagen via ntg-context:
>>
>> local sum = string.format("%0.2f", (0.3 * 100))
>>
>> Gives 30.00
>>
>> how do I get 30,00
> 
> local sum = string.formatters["%0.2M"](0.3 * 100)

Thanks a lot, Hans.

I can't find "string.formatters" and the format string %0.2M online or 
in the Lua-Manual. Any hint where I can find more about this? As commas 
as decimal separator might be a common wish, I would like to document it 
somewhere in the Wiki, if I could find some context.

Ciao!
juh

___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / https://mailman.ntg.nl/mailman3/lists/ntg-context.ntg.nl
webpage  : https://www.pragma-ade.nl / https://context.aanhet.net (mirror)
archive  : https://github.com/contextgarden/context
wiki     : https://wiki.contextgarden.net
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [NTG-context] Re: max function in spreadsheettable
  2024-10-15 19:37       ` juh+ntg-context--- via ntg-context
@ 2024-10-15 19:58         ` Wolfgang Schuster
  2024-10-16  5:43           ` juh+ntg-context--- via ntg-context
  2024-10-15 20:04         ` Henning Hraban Ramm
  1 sibling, 1 reply; 11+ messages in thread
From: Wolfgang Schuster @ 2024-10-15 19:58 UTC (permalink / raw)
  To: mailing list for ConTeXt users, juh+ntg-context--- via ntg-context

juh+ntg-context--- via ntg-context schrieb am 15.10.2024 um 21:37:
> Am 15.10.24 um 17:16 schrieb Hans Hagen via ntg-context:
>>>
>>> local sum = string.format("%0.2f", (0.3 * 100))
>>>
>>> Gives 30.00
>>>
>>> how do I get 30,00
>>
>> local sum = string.formatters["%0.2M"](0.3 * 100)
>
> Thanks a lot, Hans.
>
> I can't find "string.formatters" and the format string %0.2M online or 
> in the Lua-Manual. Any hint where I can find more about this? As 
> commas as decimal separator might be a common wish, I would like to 
> document it somewhere in the Wiki, if I could find some context.

The function is documented in the "Context Lua documents" (cld-mkiv.pdf) 
manual.

Wolfgang

___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / https://mailman.ntg.nl/mailman3/lists/ntg-context.ntg.nl
webpage  : https://www.pragma-ade.nl / https://context.aanhet.net (mirror)
archive  : https://github.com/contextgarden/context
wiki     : https://wiki.contextgarden.net
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [NTG-context] Re: max function in spreadsheettable
  2024-10-15 19:37       ` juh+ntg-context--- via ntg-context
  2024-10-15 19:58         ` Wolfgang Schuster
@ 2024-10-15 20:04         ` Henning Hraban Ramm
  1 sibling, 0 replies; 11+ messages in thread
From: Henning Hraban Ramm @ 2024-10-15 20:04 UTC (permalink / raw)
  To: ntg-context

Am 15.10.24 um 21:37 schrieb juh+ntg-context--- via ntg-context:
> Am 15.10.24 um 17:16 schrieb Hans Hagen via ntg-context:
>>>
>>> local sum = string.format("%0.2f", (0.3 * 100))
>>>
>>> Gives 30.00
>>>
>>> how do I get 30,00
>>
>> local sum = string.formatters["%0.2M"](0.3 * 100)
> 
> Thanks a lot, Hans.
> 
> I can't find "string.formatters" and the format string %0.2M online or 
> in the Lua-Manual. Any hint where I can find more about this? As commas 
> as decimal separator might be a common wish, I would like to document it 
> somewhere in the Wiki, if I could find some context.

For decimal comma in \unit and \digits, see

https://wiki.contextgarden.net/Command/setupunit [method=1] % or 3
and \setdigitmode{1} which is not documented (apparently missing in 
interface, at least in the wiki version).

Hraban
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / https://mailman.ntg.nl/mailman3/lists/ntg-context.ntg.nl
webpage  : https://www.pragma-ade.nl / https://context.aanhet.net (mirror)
archive  : https://github.com/contextgarden/context
wiki     : https://wiki.contextgarden.net
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [NTG-context] Re: max function in spreadsheettable
  2024-10-15 19:58         ` Wolfgang Schuster
@ 2024-10-16  5:43           ` juh+ntg-context--- via ntg-context
  0 siblings, 0 replies; 11+ messages in thread
From: juh+ntg-context--- via ntg-context @ 2024-10-16  5:43 UTC (permalink / raw)
  To: Wolfgang Schuster, mailing list for ConTeXt users; +Cc: juh+ntg-context

Am 15.10.24 um 21:58 schrieb Wolfgang Schuster:
> The function is documented in the "Context Lua documents" (cld-mkiv.pdf) 
> manual.
Indeed. Obviously I was way too tired yesterday.
Thanks!
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / https://mailman.ntg.nl/mailman3/lists/ntg-context.ntg.nl
webpage  : https://www.pragma-ade.nl / https://context.aanhet.net (mirror)
archive  : https://github.com/contextgarden/context
wiki     : https://wiki.contextgarden.net
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [NTG-context] string.formatters (was: Re: max function in spreadsheettable)
  2024-10-15 15:16     ` Hans Hagen via ntg-context
  2024-10-15 19:37       ` juh+ntg-context--- via ntg-context
@ 2024-11-14  7:59       ` juh+ntg-context--- via ntg-context
  2024-11-14  8:18         ` [NTG-context] Re: string.formatters juh+ntg-context--- via ntg-context
  1 sibling, 1 reply; 11+ messages in thread
From: juh+ntg-context--- via ntg-context @ 2024-11-14  7:59 UTC (permalink / raw)
  To: ntg-context; +Cc: juh+ntg-context

Am 15.10.24 um 17:16 schrieb Hans Hagen via ntg-context:
> On 10/15/2024 2:33 PM, juh+ntg-context--- via ntg-context wrote:

> local sum = string.formatters["%0.2M"](0.3 * 100)

This does not work here with numbers with more than three digits.

\starttext
\startluacode
context(string.formatters["%0.2M"](1000))
\stopluacode
\stoptext

Gives 10.2000,00

juh
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / https://mailman.ntg.nl/mailman3/lists/ntg-context.ntg.nl
webpage  : https://www.pragma-ade.nl / https://context.aanhet.net (mirror)
archive  : https://github.com/contextgarden/context
wiki     : https://wiki.contextgarden.net
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [NTG-context] Re: string.formatters
  2024-11-14  7:59       ` [NTG-context] string.formatters (was: Re: max function in spreadsheettable) juh+ntg-context--- via ntg-context
@ 2024-11-14  8:18         ` juh+ntg-context--- via ntg-context
  2024-11-14 18:23           ` Wolfgang Schuster
  0 siblings, 1 reply; 11+ messages in thread
From: juh+ntg-context--- via ntg-context @ 2024-11-14  8:18 UTC (permalink / raw)
  To: ntg-context; +Cc: juh+ntg-context

Am 14.11.24 um 08:59 schrieb juh+ntg-context--- via ntg-context:
> \starttext
> \startluacode
> context(string.formatters["%0.2M"](1000))
> \stopluacode
> \stoptext
> 
> Gives 10.2000,00

context(string.formatters["%M"](1000))

Gives the right result. But I am still confused.

juh
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / https://mailman.ntg.nl/mailman3/lists/ntg-context.ntg.nl
webpage  : https://www.pragma-ade.nl / https://context.aanhet.net (mirror)
archive  : https://github.com/contextgarden/context
wiki     : https://wiki.contextgarden.net
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [NTG-context] Re: string.formatters
  2024-11-14  8:18         ` [NTG-context] Re: string.formatters juh+ntg-context--- via ntg-context
@ 2024-11-14 18:23           ` Wolfgang Schuster
  0 siblings, 0 replies; 11+ messages in thread
From: Wolfgang Schuster @ 2024-11-14 18:23 UTC (permalink / raw)
  To: mailing list for ConTeXt users, juh+ntg-context--- via ntg-context

juh+ntg-context--- via ntg-context schrieb am 14.11.2024 um 09:18:
> Am 14.11.24 um 08:59 schrieb juh+ntg-context--- via ntg-context:
>> \starttext
>> \startluacode
>> context(string.formatters["%0.2M"](1000))
>> \stopluacode
>> \stoptext
>>
>> Gives 10.2000,00
>
> context(string.formatters["%M"](1000))
>
> Gives the right result. But I am still confused.
You can't specify the precision but it's possible to set the thousand 
separator
(no idea for the rule what can be used as separator).

\starttext
\cldcontext{string.formatters["\letterpercent .m"](1)}
\cldcontext{string.formatters["\letterpercent .m"](10)}
\cldcontext{string.formatters["\letterpercent .m"](100)}
\cldcontext{string.formatters["\letterpercent .m"](1000)}
\cldcontext{string.formatters["\letterpercent .m"](10000)}
\cldcontext{string.formatters["\letterpercent .m"](100000)}
\cldcontext{string.formatters["\letterpercent .m"](1000000)}
\cldcontext{string.formatters["\letterpercent .m"](10000000)}
\cldcontext{string.formatters["\letterpercent .m"](100000000)}
\stoptext

Wolfgang

___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / https://mailman.ntg.nl/mailman3/lists/ntg-context.ntg.nl
webpage  : https://www.pragma-ade.nl / https://context.aanhet.net (mirror)
archive  : https://github.com/contextgarden/context
wiki     : https://wiki.contextgarden.net
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2024-11-14 18:24 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-10-15  8:59 [NTG-context] max function in spreadsheettable juh+ntg-context--- via ntg-context
2024-10-15 10:42 ` [NTG-context] " Henning Hraban Ramm
2024-10-15 12:33   ` juh+ntg-context--- via ntg-context
2024-10-15 15:16     ` Hans Hagen via ntg-context
2024-10-15 19:37       ` juh+ntg-context--- via ntg-context
2024-10-15 19:58         ` Wolfgang Schuster
2024-10-16  5:43           ` juh+ntg-context--- via ntg-context
2024-10-15 20:04         ` Henning Hraban Ramm
2024-11-14  7:59       ` [NTG-context] string.formatters (was: Re: max function in spreadsheettable) juh+ntg-context--- via ntg-context
2024-11-14  8:18         ` [NTG-context] Re: string.formatters juh+ntg-context--- via ntg-context
2024-11-14 18:23           ` Wolfgang Schuster

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).