Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!uunet!zephyr.ens.tek.com!uw-beaver!ubc-cs!alberta!edson!news From: eric@ee.ualberta.ca (Eric Norum) Newsgroups: comp.std.c Subject: Question about printf %g format Keywords: printf, floating point Message-ID: <1991Jan8.031801.28996@ee.ualberta.ca> Date: 8 Jan 91 03:18:01 GMT Sender: news@ee.ualberta.ca Reply-To: eric@ee.ualberta.ca (Eric Norum) Organization: University of Alberta Electrical Engineering Lines: 24 I have a question about printf's `%g' format. Specifically, what should #include main () { printf ("%.3g\n", 0.0001234); } print? It seems to me that leading zero's shouldn't count as significant when printf chooses to use `f' format ..... so `0.000123' should be printed. The HP-UX and Sun 4.1 machines here agree with me, but some other systems choose to print `0'. (!!!) I hope the latter behaviour is wrong, but when I read K&R II page 244 I'm not sure. Is the `correct' behaviour documented somewhere? -- Eric Norum Dept. of Electrical Engineering eric@ee.ualberta.ca University of Alberta Edmonton, Canada. phone: (403) 492-4626