Folks, last changes to number formatting in luatex makes things somewhat confusing. Please consider the following. \directlua{ local floor = math.floor local round = function(n) return floor(10000*n+0.5)/10000 end n = math.pi % generic round doesn't work anymore, print() io.write(round(n)) % but explicit conversion to string helps print() io.write(round(n).."") % now lets take more pleasant n n = 100.4 % now the explicit conversion to string doesn't help either print() print(round(n)) % same with pdf.print, tex.write pdf.print(round(n)) tex.write(round(n)) }?\end This is hardly controlable, as the same operations gives completelly different results for n=10.4 and n=100.4. Obviously much depends on internal representation of the number, but one never had to bother before. The reason I'm concerned is that string.format() function allows only fixed decimal digits "%.<n>f" or fixed all the digits "%.<n>g". And what is actually needed in most cases is "round to <n> digits and omit extra zeros at the end". That is why I tend to use floor(scale*n+0.5)/scale for rounding, which is not a good solution any longer. Can one advice how to write rounded numbers without extra zeros? Thanks, Paweł -- Pawe/l Jackowski P.Jackowski@gust.org.pl
Paweł Jackowski wrote:
Folks,
last changes to number formatting in luatex makes things somewhat confusing. Please consider the following.
Hans asked for more precision in tostring() for small numbers, and this was the result. Please try the latest trunk, which uses a somewhat different approach ands seems to be more reliable. Best wishes, Taco
Hi,
Hans asked for more precision in tostring() for small numbers, and this was the result. Please try the latest trunk, which uses a somewhat different approach ands seems to be more reliable.
All cases I tried gives neat results by now.
%.99g
Round the number explicitly and use enough digits in %g format to cover all. You're right. Thank you! -- Pawe/l Jackowski P.Jackowski@gust.org.pl
Paweł Jackowski wrote:
Can one advice how to write rounded numbers without extra zeros?
%.99g ----------------------------------------------------------------- Hans Hagen | PRAGMA ADE Ridderstraat 27 | 8061 GH Hasselt | The Netherlands tel: 038 477 53 69 | fax: 038 477 53 74 | www.pragma-ade.com | www.pragma-pod.nl -----------------------------------------------------------------
participants (3)
-
Hans Hagen
-
Paweł Jackowski
-
Taco Hoekwater