From da8162d4e816cf49d9790a1c81556b499f442bed Mon Sep 17 00:00:00 2001 From: Hans Hagen Date: Fri, 22 Jun 2018 16:42:14 +0200 Subject: 2018-06-22 16:02:00 --- tex/context/base/mkiv/util-str.lua | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'tex/context/base/mkiv/util-str.lua') diff --git a/tex/context/base/mkiv/util-str.lua b/tex/context/base/mkiv/util-str.lua index 5317da423..f575050ff 100644 --- a/tex/context/base/mkiv/util-str.lua +++ b/tex/context/base/mkiv/util-str.lua @@ -612,6 +612,7 @@ local sequenced=table.sequenced local formattednumber=number.formatted local sparseexponent=number.sparseexponent local formattedfloat=number.formattedfloat +local stripper=lpeg.patterns.stripzeros ]] else @@ -639,6 +640,7 @@ else formattednumber = number.formatted, sparseexponent = number.sparseexponent, formattedfloat = number.formattedfloat, + stripper = lpeg.patterns.stripzeros, } end @@ -907,9 +909,18 @@ local format_n = function() -- strips leading and trailing zeros and removes .0 return format("((a%s %% 1 == 0) and format('%%i',a%s) or tostring(a%s))",n,n,n) end +-- local format_N = function() -- strips leading and trailing zeros (also accepts string) +-- n = n + 1 +-- return format("tostring(tonumber(a%s) or a%s)",n,n) +-- end + local format_N = function() -- strips leading and trailing zeros (also accepts string) n = n + 1 - return format("tostring(tonumber(a%s) or a%s)",n,n) + if not f or f == "" then + return format("(((a%s > -0.0000000005 and a%s < 0.0000000005) and '0') or ((a%s %% 1 == 0) and format('%%i',a%s)) or lpegmatch(stripper,format('%%.9f',a%s)))",n,n,n,n,n) + else + return format("(((a%s %% 1 == 0) and format('%%i',a%s)) or lpegmatch(stripper,format('%%%sf',a%s)))",n,n,f,n) + end end local format_a = function(f) -- cgit v1.2.3