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
___________________________________________________________________________________
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
___________________________________________________________________________________

Reply via email to