[metapost] Decimal numbers

Dirk Laurie dirk.laurie at gmail.com
Sat Nov 12 07:28:05 CET 2011

2011/11/10 Andrej Kastrin <andrej.kastrin at yahoo.com>:

> I wonder how to get a number rounded to a desired number of decimal places.

*def rnd(expr x,d) = round(x*(10**d))/(10**d) enddef;

*show rnd(sqrt(2),3);
>> 1.414

> Thanks in advance for any pointers and/or suggestions.
This sort of thing is in the Metafont Book by Donald Knuth and not
repeated in the Metapost manual.


More information about the metapost mailing list