Path: csiph.com!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder2.enfer-du-nord.net!fu-berlin.de!uni-berlin.de!news.dfncis.de!not-for-mail From: =?UTF-8?B?SGFucy1CZXJuaGFyZCBCcsO2a2Vy?= Newsgroups: comp.graphics.apps.gnuplot Subject: Re: How to print floats with leading blanks instead of leading zeros using sprintf? Date: Tue, 29 May 2012 18:33:00 +0200 Lines: 28 Message-ID: References: <3d97629a-6d13-4e42-bb08-9a1d05a569d9@vy7g2000pbc.googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Trace: news.dfncis.de ug1tq/1OAJEK5xjVsDkjmwH6zyXVU5uBzCgooGNRli5L/6A/enc2mozc55CW7onu1FPth3hyAs Cancel-Lock: sha1:2jFWtkBT2A1HggIoO3ENc91nZns= User-Agent: Mozilla/5.0 (Windows NT 6.1; rv:12.0) Gecko/20120420 Thunderbird/12.0 In-Reply-To: Xref: csiph.com comp.graphics.apps.gnuplot:1161 On 29.05.2012 04:56, valerasimonov@gmail.com wrote: [...] >>> However gnuplot outputs: sprintf(' %3.0f',1) "001" >> No, it doesn't. [...] > What I want to print is " 1". Do you know how this task can be > accomplished? You already knew yourself --- the command you tried did (pretty much) exactly that. You just misinterpreted the actual result you saw because you looked at it in a proportional-font output format. > About integers you are right again. But doesn't (although with > warnings) C transform int to float when necessary? Not in these cases it wouldn't. Variadic functions don't give the compiler the information to apply such transformations automatically. So if you tried a stunt like printf("5.3f", 3) in a C program, you would be giving the compiler and/or compiled program a legit excuse to do whatever it pleases (the technical term is "undefined behaviour"). But that's rather beside the point, since you're using gnuplot here, not C. Yes, gnuplot is designed to imitate C, but the analogy cannot be perfect. gnuplot will convert automatically from float to integer and vice versa, both without a warning. It can do that because unlike C it has information about the type of things even at run time.