Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.graphics.apps.gnuplot > #1153

Re: How to print floats with leading blanks instead of leading zeros using sprintf?

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 2012-05-28 19:56 -0700
Organization http://groups.google.com
Message-ID <b987673d-4d34-4b67-b565-a77ccb766f3c@googlegroups.com> (permalink)
References <3d97629a-6d13-4e42-bb08-9a1d05a569d9@vy7g2000pbc.googlegroups.com> <a2i989FfaaU1@mid.dfncis.de>

Show all headers | View raw


On Monday, May 28, 2012 5:32:58 PM UTC-4, Hans-Bernhard Bröker wrote:
> On 28.05.2012 17:09, Валерий Симонов wrote:
> 
> > 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".
> 
> That reference (or your understanding of it) is incorrect, as far as the 
> behaviour of the 'f' format specifier is concerned.
> 
> > However gnuplot outputs:
> > sprintf(' %3.0f',1)  "001"
> 
> No, it doesn't.
> 
> > sprintf(' %3.0d',1) "1" (without leading blanks).
> 
> > Does anyone know how to fix this issue?
> 
> What issue, in particular?
> 
> How come your subject line is about blanks in printing _floats_, but 
> then you only try syntax that you think you should print leading blanks 
> 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 accomplished?

About integers you are right again. But doesn't (although with warnings) C transform int to float when necessary?

Back to comp.graphics.apps.gnuplot | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

How to print floats with leading blanks instead of leading zeros using sprintf? Валерий Симонов <valerasimonov@gmail.com> - 2012-05-28 08:09 -0700
  Re: How to print floats with leading blanks instead of leading zeros using sprintf? sfeam <sfeam@users.sourceforge.net> - 2012-05-28 11:16 -0700
    Re: How to print floats with leading blanks instead of leading zeros using sprintf? Валерий Симонов <valerasimonov@gmail.com> - 2012-05-28 19:33 -0700
      Re: How to print floats with leading blanks instead of leading zeros using sprintf? sfeam <sfeam@users.sourceforge.net> - 2012-05-28 20:48 -0700
        Re: How to print floats with leading blanks instead of leading zeros using sprintf? valerasimonov@gmail.com - 2012-05-29 06:18 -0700
    Re: How to print floats with leading blanks instead of leading zeros using sprintf? valerasimonov@gmail.com - 2012-05-28 20:19 -0700
  Re: How to print floats with leading blanks instead of leading zeros   using sprintf? Hans-Bernhard Bröker <HBBroeker@t-online.de> - 2012-05-28 23:32 +0200
    Re: How to print floats with leading blanks instead of leading zeros using sprintf? valerasimonov@gmail.com - 2012-05-28 19:56 -0700
      Re: How to print floats with leading blanks instead of leading zeros   using sprintf? Hans-Bernhard Bröker <HBBroeker@t-online.de> - 2012-05-29 18:33 +0200
        Re: How to print floats with leading blanks instead of leading zeros using sprintf? valerasimonov@gmail.com - 2012-05-31 05:43 -0700
  Re: How to print floats with leading blanks instead of leading zeros using sprintf? Christoph Bersch <usenet@bersch.net> - 2012-05-29 09:51 +0200
    Re: How to print floats with leading blanks instead of leading zeros using sprintf? valerasimonov@gmail.com - 2012-05-29 06:19 -0700

csiph-web