Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!wuarchive!uunet!mcsun!ukc!pyrltd!tetrauk!rick From: rick@tetrauk.UUCP (Rick Jones) Newsgroups: comp.lang.c Subject: Re: **** a simple question **** Message-ID: <733@tetrauk.UUCP> Date: 18 Sep 90 11:42:53 GMT References: <793@babcock.cerc.wvu.wvnet.edu> Reply-To: rick@tetrauk.UUCP (Rick Jones) Organization: Tetra Ltd., Maidenhead, UK Lines: 32 In article <793@babcock.cerc.wvu.wvnet.edu> siping@cathedral.cerc.wvu.wvnet.edu (Siping Liu) writes: >How can I print out ONLY the significant digits of >a float number? As you know, "%f" fills in zero's if >the number does not have enough non-zero digits after >the point. Ever tried the "%g" format? e.g. printf ("%g", x); You can control the number of significant digits with e.g.: printf ("%.10g", x); note the parameter is significant digits, NOT decimal places IEEE doubles are not generally reliable beyond 15 sig. digits, so printf ("%.15g", x); will give you only significant digits, up to the maximum effective precision For very large or very small numbers, this format defaults to the equivalent of %e or %f respectively. For more info, read the manual! -- Rick Jones Nothing ever happens, nothing happens at all Tetra Ltd. The needle returns to the start of the song Maidenhead, Berks, UK And we all sing along like before rick@tetrauk.uucp - Del Amitri