From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.comp.tex.context/54861 Path: news.gmane.org!not-for-mail From: Curiouslearn Newsgroups: gmane.comp.tex.context Subject: Re: Metapost label - Truncating digits after decimal point Date: Sun, 29 Nov 2009 09:47:33 -0500 Message-ID: <3b4b12310911290647m3a18b2bt80fe2f12eb742d3b@mail.gmail.com> References: <3b4b12310911280656x6c4b5023g112ba92b278d5df4@mail.gmail.com> <4B1231AD.7090409@elvenkind.com> Reply-To: mailing list for ConTeXt users NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable X-Trace: ger.gmane.org 1259506076 7509 80.91.229.12 (29 Nov 2009 14:47:56 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sun, 29 Nov 2009 14:47:56 +0000 (UTC) To: mailing list for ConTeXt users Original-X-From: ntg-context-bounces@ntg.nl Sun Nov 29 15:47:49 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 1NEl41-0001C9-9x for gctc-ntg-context-518@m.gmane.org; Sun, 29 Nov 2009 15:47:49 +0100 Original-Received: from localhost (localhost [127.0.0.1]) by balder.ntg.nl (Postfix) with ESMTP id 12CAFC9BB2; Sun, 29 Nov 2009 15:44:42 +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 ZrNid2m9wjSS; Sun, 29 Nov 2009 15:44:39 +0100 (CET) Original-Received: from balder.ntg.nl (localhost [127.0.0.1]) by balder.ntg.nl (Postfix) with ESMTP id 55395C9C92; Sun, 29 Nov 2009 15:44:39 +0100 (CET) Original-Received: from localhost (localhost [127.0.0.1]) by balder.ntg.nl (Postfix) with ESMTP id 820F9C9C92 for ; Sun, 29 Nov 2009 15:44:37 +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 sooD-iduJNUv for ; Sun, 29 Nov 2009 15:44:34 +0100 (CET) Original-Received: from mail-pz0-f179.google.com (mail-pz0-f179.google.com [209.85.222.179]) by balder.ntg.nl (Postfix) with ESMTP id 0D7E4C9BB2 for ; Sun, 29 Nov 2009 15:44:33 +0100 (CET) Original-Received: by pzk9 with SMTP id 9so1893741pzk.16 for ; Sun, 29 Nov 2009 06:47:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:in-reply-to:references :date:message-id:subject:from:to:content-type :content-transfer-encoding; bh=28JAr1c4b0itAtBJQtBeolRGD5ChCS54JczLaubvq4A=; b=lT3LL1YwR0S4kq3BYvPW9o+2iCzYfMT+FWxOLV6YYdknJwPdsIGdlZd8BtX0W5q9eA 4e6xb+3znvZpB5NoRw2x1r42zztw/1MAJmZguqmiydRxu4JO7PfjHNwcA24Hr4Csb3g2 OfCZaCCI6I+J3VYaUq73QXJHA3DWTKJZ1EFHY= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type:content-transfer-encoding; b=JgSqo1gq0vVxzG2EWbdL1u9DKe4QIMaZ3U9dQdlpBNsZALM8teJiMkLpxE8iVVRi4z xZdT3/qWu+Giajh/ZNHkKM2zHNsdMgYTQp78ce4dpoMUGx/r4v87quDQN2pWopsXq47W u6Cn159a+wE1ot8jt5TTzydsxqdwN+o7Z8z5Y= Original-Received: by 10.142.249.6 with SMTP id w6mr315527wfh.346.1259506053598; Sun, 29 Nov 2009 06:47:33 -0800 (PST) In-Reply-To: <4B1231AD.7090409@elvenkind.com> 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:54861 Archived-At: Thanks so much, Taco. I will try out the code below. Good to know that Metapost has functions such as substring. On Sun, Nov 29, 2009 at 3:32 AM, Taco Hoekwater wrote: > 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) =3D > =A0hide( > =A0 =A0string s, tmp; > =A0 =A0numeric ii, e; > =A0 =A0e :=3D -1; > =A0 =A0for i=3D1 upto length(origs): > =A0 =A0 =A0ii :=3D i; > =A0 =A0 =A0tmp :=3D substring (i-1,i) of origs; > =A0 =A0 =A0if tmp =3D ".": if n=3D0: ii:=3Dii-1; exitif true; fi e:=3D0; = fi > =A0 =A0 =A0if e>=3D0: e :=3D e+1; exitif e>n; =A0fi > =A0 =A0endfor; > =A0 =A0s:=3Dsubstring(0,ii) of origs; ) > =A0s > 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: > > =A0label.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 =A0: http://www.pragma-ade.nl / http://tex.aanhet.net > archive =A0: http://foundry.supelec.fr/projects/contextrev/ > wiki =A0 =A0 : http://contextgarden.net > _________________________________________________________________________= __________ > ___________________________________________________________________________= ________ If your question is of interest to others as well, please add an entry to t= he Wiki! maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-cont= ext webpage : http://www.pragma-ade.nl / http://tex.aanhet.net archive : http://foundry.supelec.fr/projects/contextrev/ wiki : http://contextgarden.net ___________________________________________________________________________= ________