Curiouslearn wrote:
Hi,

Is it possible to truncate the digits after decimal point in Metapost
when using textext()? Please see the minimal example below which
produces 1.84375. Can I just keep the first digit and have it produce
1.8 ?

Here is a helper macro for you:

def trunc_digits(expr n, origs) =
  hide(
    string s, tmp;
    numeric ii, e;
    e := -1;
    for i=1 upto length(origs):
      ii := i;
      tmp := substring (i-1,i) of origs;
      if tmp = ".": if n=0: ii:=ii-1; exitif true; fi e:=0; fi
      if e>=0: e := e+1; exitif e>n;  fi
    endfor;
    s:=substring(0,ii) of origs; )
  s
enddef;


When run this macro with the result of decimal() as second argument,
it will create a new string as many fractional digits as you specify
in the first argument:

  label.lft(textext(trunc_digits(1,decimal f(5))),(0,f(5)) scaled u);   

Best wishes,
Taco
___________________________________________________________________________________
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://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki     : http://contextgarden.net
___________________________________________________________________________________

Reply via email to