Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.glorb.com!news-out.readnews.com!transit3.readnews.com!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail From: valerasimonov@gmail.com Newsgroups: comp.graphics.apps.gnuplot Subject: Re: How to print floats with leading blanks instead of leading zeros using sprintf? Date: Mon, 28 May 2012 19:56:58 -0700 (PDT) Organization: http://groups.google.com Lines: 41 Message-ID: References: <3d97629a-6d13-4e42-bb08-9a1d05a569d9@vy7g2000pbc.googlegroups.com> NNTP-Posting-Host: 132.206.126.41 Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Trace: posting.google.com 1338260219 5551 127.0.0.1 (29 May 2012 02:56:59 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Tue, 29 May 2012 02:56:59 +0000 (UTC) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=132.206.126.41; posting-account=4Nx8HQoAAACPrCgQ4Rd61O9cDhaTWCLL User-Agent: G2/1.0 Xref: csiph.com comp.graphics.apps.gnuplot:1153 On Monday, May 28, 2012 5:32:58 PM UTC-4, Hans-Bernhard Br=C3=B6ker wrote: > On 28.05.2012 17:09, =D0=92=D0=B0=D0=BB=D0=B5=D1=80=D0=B8=D0=B9 =D0=A1=D0= =B8=D0=BC=D0=BE=D0=BD=D0=BE=D0=B2 wrote: >=20 > > I want to specify labels for the plots using sprintf. > > According to http://www.cplusplus.com/reference/clibrary/cstdio/sprintf= / > > sprintf(' %3.0f',1) should print "001" > > sprintf(' %3.0d',1) should print " 1". >=20 > That reference (or your understanding of it) is incorrect, as far as the= =20 > behaviour of the 'f' format specifier is concerned. >=20 > > However gnuplot outputs: > > sprintf(' %3.0f',1) "001" >=20 > No, it doesn't. >=20 > > sprintf(' %3.0d',1) "1" (without leading blanks). >=20 > > Does anyone know how to fix this issue? >=20 > What issue, in particular? >=20 > How come your subject line is about blanks in printing _floats_, but=20 > then you only try syntax that you think you should print leading blanks= =20 > in _integers_? Thank you for your reply. You are right sprintf(' %03.0f',1) should print "001" (not sprintf(' %3.0f'= ,1)). Do you agree it makes sense? What I want to print is " 1". Do you know how this task can be accomplishe= d? About integers you are right again. But doesn't (although with warnings) C = transform int to float when necessary?