Hello, I do not know Lua but I'll learn later. How to display only 3 digits after the decimal point ? thank you, Fabrice \starttext \startlinecorrection[blank] \startmidaligned \bTABLE[width=2cm,offset=0.8ex,align={lohi,middle}] \bTR \bTD \math{P} \eTD \bTD \math{m} \eTD \bTD \math{g_M} \eTD \eTR \bTR \bTD \math{1.6} \eTD \bTD \math{0.4} \eTD \bTD \startluacode context(1.6/0.4)\stopluacode \eTD \eTR \bTR \bTD \math{3.1} \eTD \bTD \math{0.8} \eTD \bTD \startluacode context(3.1/0.8)\stopluacode \eTD \eTR \bTR \bTD \math{4.3} \eTD \bTD \math{1.2} \eTD \bTD \startluacode context(4.3/1.2) \stopluacode \eTD \eTR \bTR \bTD \math{5.8} \eTD \bTD \math{1.6} \eTD \bTD \startluacode context(5.8/1.6)\stopluacode \eTD \eTR \bTR \bTD \math{7.5} \eTD \bTD \math{2} \eTD \bTD \startluacode context(7.5/2)\stopluacode \eTD \eTR \eTABLE \stopmidaligned \stoplinecorrection \stoptext
Hi Fabrice, You can use a construction such as: \starttext \ctxlua{x = math.floor(10^3*math.pi)/10^3; context(x)} \stoptext Best regards: OK
On 19 Apr 2017, at 15:25, Fabrice Couvreur
wrote: Hello, I do not know Lua but I'll learn later. How to display only 3 digits after the decimal point ? thank you, Fabrice
\starttext \startlinecorrection[blank] \startmidaligned \bTABLE[width=2cm,offset=0.8ex,align={lohi,middle}] \bTR \bTD \math{P} \eTD \bTD \math{m} \eTD \bTD \math{g_M} \eTD \eTR \bTR \bTD \math{1.6} \eTD \bTD \math{0.4} \eTD \bTD \startluacode context(1.6/0.4)\stopluacode \eTD \eTR \bTR \bTD \math{3.1} \eTD \bTD \math{0.8} \eTD \bTD \startluacode context(3.1/0.8)\stopluacode \eTD \eTR \bTR \bTD \math{4.3} \eTD \bTD \math{1.2} \eTD \bTD \startluacode context(4.3/1.2) \stopluacode \eTD \eTR \bTR \bTD \math{5.8} \eTD \bTD \math{1.6} \eTD \bTD \startluacode context(5.8/1.6)\stopluacode \eTD \eTR \bTR \bTD \math{7.5} \eTD \bTD \math{2} \eTD \bTD \startluacode context(7.5/2)\stopluacode \eTD \eTR \eTABLE \stopmidaligned \stoplinecorrection \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 ___________________________________________________________________________________
Hello,
do you mean this? - It shows EXACTLY 3 digits after the decimal point:
----
\cldcontext{string.format("\letterpercent.3f", 5.8/1.6)}
\cldcontext{string.format(string.char(37) .. ".3f", 5.8/1.6)}
\startluacode
context(string.format("%.3f", 5.8/1.6))
\stopluacode
----
Best regards,
Lukas
On Wed, 19 Apr 2017 15:25:07 +0200, Fabrice Couvreur
Hello, I do not know Lua but I'll learn later. How to display only 3 digits after the decimal point ? thank you, Fabrice
\starttext \startlinecorrection[blank] \startmidaligned \bTABLE[width=2cm,offset=0.8ex,align={lohi,middle}] \bTR \bTD \math{P} \eTD \bTD \math{m} \eTD \bTD \math{g_M} \eTD \eTR \bTR \bTD \math{1.6} \eTD \bTD \math{0.4} \eTD \bTD \startluacode context(1.6/0.4)\stopluacode \eTD \eTR \bTR \bTD \math{3.1} \eTD \bTD \math{0.8} \eTD \bTD \startluacode context(3.1/0.8)\stopluacode \eTD \eTR \bTR \bTD \math{4.3} \eTD \bTD \math{1.2} \eTD \bTD \startluacode context(4.3/1.2) \stopluacode \eTD \eTR \bTR \bTD \math{5.8} \eTD \bTD \math{1.6} \eTD \bTD \startluacode context(5.8/1.6)\stopluacode \eTD \eTR \bTR \bTD \math{7.5} \eTD \bTD \math{2} \eTD \bTD \startluacode context(7.5/2)\stopluacode \eTD \eTR \eTABLE \stopmidaligned \stoplinecorrection \stoptext
-- Ing. Lukáš Procházka | mailto:LPr@pontex.cz Pontex s. r. o. | mailto:pontex@pontex.cz | http://www.pontex.cz | IDDS:nrpt3sn Bezová 1658 147 14 Praha 4 Tel: +420 241 096 751 (+420 720 951 172) Fax: +420 244 461 038
On Wed, 19 Apr 2017, Procházka Lukáš Ing. wrote:
Hello,
do you mean this? - It shows EXACTLY 3 digits after the decimal point:
---- \cldcontext{string.format("\letterpercent.3f", 5.8/1.6)}
\cldcontext{string.format(string.char(37) .. ".3f", 5.8/1.6)}
\startluacode context(string.format("%.3f", 5.8/1.6)) \stopluacode
\startluacode context("%0.3f", 5.8/1.6) \stopluacode is simpler. Also see: http://wiki.contextgarden.net/Programming_in_LuaTeX#Arithmetic_without_using... Aditya
Am 19.04.2017 um 15:25 schrieb Fabrice Couvreur:
I do not know Lua but I'll learn later. How to display only 3 digits after the decimal point ?
The default is 3 digits \startluacode function round(a,dec) local dec = dec or 3 local b = math.pow(10,dec) return math.floor(a*b)/b end \stopluacode \starttext \startlinecorrection[blank] \startmidaligned \bTABLE[width=2cm,offset=0.8ex,align={lohi,middle}] \bTR \bTD \math{P} \eTD \bTD \math{m} \eTD \bTD \math{g_M} \eTD \eTR \bTR \bTD \math{1.6} \eTD \bTD \math{0.4} \eTD \bTD \startluacode context(round(1.6/0.4,1))\stopluacode \eTD \eTR \bTR \bTD \math{3.1} \eTD \bTD \math{0.8} \eTD \bTD \startluacode context(round(3.1/0.8))\stopluacode \eTD \eTR \bTR \bTD \math{4.3} \eTD \bTD \math{1.2} \eTD \bTD \startluacode context(round(4.3/1.2,2)) \stopluacode \eTD \eTR \bTR \bTD \math{5.8} \eTD \bTD \math{1.6} \eTD \bTD \startluacode context(5.8/1.6)\stopluacode \eTD \eTR \bTR \bTD \math{7.5} \eTD \bTD \math{2} \eTD \bTD \startluacode context(7.5/2)\stopluacode \eTD \eTR \eTABLE \stopmidaligned \stoplinecorrection \stoptext Herbert
participants (5)
-
Aditya Mahajan
-
Fabrice Couvreur
-
Herbert Voss
-
Otared Kavian
-
Procházka Lukáš Ing.