max function in spreadsheettable
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.
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
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 -----------------------------------------------------------------
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
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
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
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
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
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
participants (4)
-
Hans Hagen
-
Henning Hraban Ramm
-
juh+ntg-context@mailbox.org
-
Wolfgang Schuster