Thanks for this solution. Sounds small and clean. I need to learn Lua I guess.



On Tue, Dec 15, 2009 at 5:34 AM, Aditya Mahajan <adit...@umich.edu> wrote:
> On Sat, 28 Nov 2009, 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 ?
>>
>> Thanks.
>
> If you are using mkiv, you can use lua to truncate a number.
>
> \unexpanded\def\truncate#1{\ctxlua{context("\%.1f", #1)}}
>
> \startMPdefinitions
>  def truncatedtext(expr s) =
>    textext("\truncate{" & s & "}")
>  enddef ;
> \stopMPdefinitions
>
> \starttext
> \startuseMPgraphic{Figure}
>  u := 1cm;
>  pickup pencircle scaled 2pt; % default pen thickness
>  %TheFunction
>  vardef f(expr x) =
>          (10/x)-x*((0.5)**x)
>  enddef;
>  %Labels
>  %label.lft(textext("\truncate{" & decimal f(5) & "}"),(0,f(5)) scaled u);
>  label.lft(truncatedtext(decimal f(5)),(0,f(5)) scaled u);
> \stopuseMPgraphic
> \useMPgraphic{Figure}
>
>
> \stoptext
>
> Aditya
> ___________________________________________________________________________________
> 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
> ___________________________________________________________________________________
>
___________________________________________________________________________________
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