[metapost] Decimal numbers

Andrej Kastrin andrej.kastrin at yahoo.com
Thu Nov 10 19:31:49 CET 2011


Dear all,

I'm a 2nd day METAPOST user. I wonder how to get a number rounded to a desired number of decimal places. A minimal example is pasted below.

beginfig(1);
xmax:=10;

ux:=0.5cm;

drawarrow (0,0)*ux..(xmax+0.7,0)*ux;

for i=0 upto xmax:

  draw (i,-0.05)*ux -- (i,0.05)*ux;

  label.bot(decimal(i/10), (i,0)*ux);

endfor;

endfig;
end

The labels in the example above are as follows:
  "0, 0.1, 0.2,..., 0.9, 1"
but the desired output is:
  "0.0, 0.1, 0.2,..., 0.9, 1.0" or even better:
".0, .1, .2,..., .9, 1.0"

Thanks in advance for any pointers and/or suggestions.

Best, Andrej




More information about the metapost mailing list