ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
From: Mojca Miklavec <mojca.miklavec.lists@gmail.com>
To: mailing list for ConTeXt users <ntg-context@ntg.nl>
Subject: Re: Metapost labeling question. Please help
Date: Fri, 3 Apr 2009 07:35:54 +0200	[thread overview]
Message-ID: <6faad9f00904022235v7728f17fs185f6d6226d6a666@mail.gmail.com> (raw)
In-Reply-To: <3b4b12310904021802o35521148t8508688ea24ea547@mail.gmail.com>

On Fri, Apr 3, 2009 at 03:02, Curiouslearn wrote:
> Hi,
> I want the labels as (0.5,0.55,0.6,0.65,0.7,...,1)
> or (0.50,0.55,0.60,0.65,0.70,...,1). Either of these two is fine.
> I tried the following code for this.
> \starttext
> \startuseMPgraphic{labeltest}
> numeric rmin,rmax;
> rmin := 0.5; rmax := 1;
> ux := 25cm; uy :=10cm;
> % draw axes
> draw (rmin,0)*ux -- (rmax+0.1,0)*ux;
> draw (rmin,0)*ux -- (rmin*ux,(1.1)*uy);
> for x = 0.5 step 0.05 until 1.1:
> label.bot(textext(decimal(x)),(x*ux,x*uy));
> endfor;
> \stopuseMPgraphic
> \useMPgraphic{labeltest}
> \stoptext
> I get (0.5,0.55, 0.6,0.65001,0.70001,0.75002,...,1.00003) instead. I don't
> understand why I get more than 2 digits after 0.6.

It's because you get exact numbers in the terms what metapost
considers exact (multiples of 2^{-something}). You have exactly the
same problem if you work with floating points with any other
programming language.

> Is there a way to
> restrict the number of digits after the decimal point.
> Thanks very much.

See page 18 of metapost manual (speaking of metapost manual present in
TeX Live):

-----
6.2 Operators

The length operator returns the number of characters in a string.
For substring construction, the ⟨of operator⟩ substring is used like this:
    substring ⟨pair expression⟩ of ⟨string primary⟩
substring (2,4) of "abcde" is "cd".
-----

You can use substring (0,4) to truncate the number. 0.5 might need
special treatment, so you either need to concatenate it with 0 at the
end or you need to check the lenght of string before using substring.

Mojca
___________________________________________________________________________________
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  : https://foundry.supelec.fr/projects/contextrev/
wiki     : http://contextgarden.net
___________________________________________________________________________________

  reply	other threads:[~2009-04-03  5:35 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-04-03  1:02 Curiouslearn
2009-04-03  5:35 ` Mojca Miklavec [this message]
2009-04-03 10:52 ` Peter Rolf
2009-04-03 12:47   ` Curiouslearn
2009-04-03 13:35     ` Wolfgang Schuster
2009-04-03 13:48       ` Curiouslearn

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=6faad9f00904022235v7728f17fs185f6d6226d6a666@mail.gmail.com \
    --to=mojca.miklavec.lists@gmail.com \
    --cc=ntg-context@ntg.nl \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).