From: Joseph Canedo <josephcanedo@gmail.com>
To: mailing list for ConTeXt users <ntg-context@ntg.nl>
Subject: Re: Problem with string.format (Lua)
Date: Sun, 14 Jan 2018 13:13:54 +0100 [thread overview]
Message-ID: <5a5b4982.39ba500a.ab110.6848@mx.google.com> (raw)
In-Reply-To: <CACyK-eqM+U7D3365XtmQ+LHa=YSnjtPcv7X-Z3pY8Zfw96LyfQ@mail.gmail.com>
[-- Attachment #1.1: Type: text/plain, Size: 854 bytes --]
Hi Fabrice,
string.format behaves more or less as C printf. You probably need to specify %.4g in 1st argument.
Hope this helps
Best
Joseph
De : Fabrice Couvreur
Envoyé le :dimanche 14 janvier 2018 13:05
À : mailing list for ConTeXt users
Objet :[NTG-context] Problem with string.format (Lua)
Hello,
I start with Lua and I try to display my result with 4 decimal places without success.
Thank you
Fabrice
\startluacode
function Binomial(n,k,p)
if k > n then return nil end
if k > n/2 then k = n - k end
numer, denom = 1, 1
for i = 1, k do
numer = numer * ( n - i + 1 )
denom = denom * i
end
return (numer/denom) * p^k * (1-p)^(n-k)
end
\stopluacode
\starttext
\ctxlua{print(string.format("%g",Binomial(100,60,0.25)))}
\stoptext
[-- Attachment #1.2: Type: text/html, Size: 3664 bytes --]
[-- Attachment #2: Type: text/plain, Size: 492 bytes --]
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!
maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage : http://www.pragma-ade.nl / http://context.aanhet.net
archive : https://bitbucket.org/phg/context-mirror/commits/
wiki : http://contextgarden.net
___________________________________________________________________________________
next prev parent reply other threads:[~2018-01-14 12:13 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-01-14 12:05 Fabrice Couvreur
2018-01-14 12:13 ` Joseph Canedo [this message]
2018-01-14 12:58 ` Hans Hagen
2018-01-14 20:50 ` Fabrice Couvreur
2018-01-14 23:02 ` Hans Hagen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=5a5b4982.39ba500a.ab110.6848@mx.google.com \
--to=josephcanedo@gmail.com \
--cc=ntg-context@ntg.nl \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).