From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.comp.tex.context/54849 Path: news.gmane.org!not-for-mail From: Taco Hoekwater Newsgroups: gmane.comp.tex.context Subject: Re: Metapost label - Truncating digits after decimal point Date: Sun, 29 Nov 2009 09:32:45 +0100 Message-ID: <4B1231AD.7090409@elvenkind.com> References: <3b4b12310911280656x6c4b5023g112ba92b278d5df4@mail.gmail.com> Reply-To: mailing list for ConTeXt users NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii"; Format="flowed" Content-Transfer-Encoding: 7bit X-Trace: ger.gmane.org 1259483589 21393 80.91.229.12 (29 Nov 2009 08:33:09 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sun, 29 Nov 2009 08:33:09 +0000 (UTC) To: mailing list for ConTeXt users Original-X-From: ntg-context-bounces@ntg.nl Sun Nov 29 09:33:03 2009 Return-path: Envelope-to: gctc-ntg-context-518@m.gmane.org Original-Received: from balder.ntg.nl ([195.12.62.10]) by lo.gmane.org with esmtp (Exim 4.50) id 1NEfDK-00069L-So for gctc-ntg-context-518@m.gmane.org; Sun, 29 Nov 2009 09:33:02 +0100 Original-Received: from localhost (localhost [127.0.0.1]) by balder.ntg.nl (Postfix) with ESMTP id 3906EC9CE7; Sun, 29 Nov 2009 09:30:01 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at balder.ntg.nl Original-Received: from balder.ntg.nl ([127.0.0.1]) by localhost (balder.ntg.nl [127.0.0.1]) (amavisd-new, port 10024) with LMTP id 3RuiFgwVmxeX; Sun, 29 Nov 2009 09:29:58 +0100 (CET) Original-Received: from balder.ntg.nl (localhost [127.0.0.1]) by balder.ntg.nl (Postfix) with ESMTP id 66FE0C9CE2; Sun, 29 Nov 2009 09:29:58 +0100 (CET) Original-Received: from localhost (localhost [127.0.0.1]) by balder.ntg.nl (Postfix) with ESMTP id 253A0C9CE2 for ; Sun, 29 Nov 2009 09:29:57 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at balder.ntg.nl Original-Received: from balder.ntg.nl ([127.0.0.1]) by localhost (balder.ntg.nl [127.0.0.1]) (amavisd-new, port 10024) with LMTP id PVpYseRdDUc4 for ; Sun, 29 Nov 2009 09:29:46 +0100 (CET) Original-Received: from smtp-vbr10.xs4all.nl (smtp-vbr10.xs4all.nl [194.109.24.30]) by balder.ntg.nl (Postfix) with ESMTP id 1005AC9C1F for ; Sun, 29 Nov 2009 09:29:45 +0100 (CET) Original-Received: from [192.168.178.26] (boo.demon.nl [82.161.175.147]) (authenticated bits=0) by smtp-vbr10.xs4all.nl (8.13.8/8.13.8) with ESMTP id nAT8Wjsg013207 for ; Sun, 29 Nov 2009 09:32:45 +0100 (CET) (envelope-from taco@elvenkind.com) User-Agent: Thunderbird 2.0.0.21 (X11/20090330) In-Reply-To: <3b4b12310911280656x6c4b5023g112ba92b278d5df4@mail.gmail.com> X-Virus-Scanned: by XS4ALL Virus Scanner X-BeenThere: ntg-context@ntg.nl X-Mailman-Version: 2.1.12 Precedence: list List-Id: mailing list for ConTeXt users List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: ntg-context-bounces@ntg.nl Errors-To: ntg-context-bounces@ntg.nl Xref: news.gmane.org gmane.comp.tex.context:54849 Archived-At: 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 ___________________________________________________________________________________