1. Why won't THIS work? (2)
- Posted by Joseph Martin <jam at EXIS.NET> Mar 10, 1997
- 1180 views
I have the sequence real with real[3] = 6.000000. When I use printf() to print i t as a floating number it displays correctly. printf(1, "%f", real[3]) gives 6.000000 BUT when I give this command: printf(1, "%d", real[3]) I get 5 as the output. Does anyone know why this occurs and what I can do about it? |**************************************| | Joseph Martin | | http://sailfish.exis.net/~jam/ | |**************************************|
2. Re: Why won't THIS work? (2)
- Posted by "Lucius L. Hilley III" <luciuslhilleyiii at JUNO.COM> Mar 10, 1997
- 1155 views
On Mon, 10 Mar 1997 15:58:12 -0500 Joseph Martin <jam at EXIS.NET> writes: > >I have the sequence real with real[3] = 6.000000. >When I use printf() to print it as a floating number it >displays correctly. > >printf(1, "%f", real[3]) gives >6.000000 > >BUT when I give this command: >printf(1, "%d", real[3]) I get 5 as the output. > >Does anyone know why this occurs and what I can do about it? > >|**************************************| >| Joseph Martin | >| http://sailfish.exis.net/~jam/ | >|**************************************| > I don't know why it occurs but I do know what you can do about it. STOP WHINNING !! I'm kidding. I hate those kind of bugs too. USE: printf(1, "%1f", real[3])--this will produce 6 It will not give you 6.0 or anything like that If you want 6.0 or 6.00 then use "%1.1f" or %1.2f" Enjoy and continue the good questions. I love to answer trivial questions. :) --Lucius Lamar Hilley III -- E-mail at luciuslhilleyiii at juno.com -- I support transfering of files less than 64K. -- I can Decode both UU and Base64 format.
3. Why won't THIS work? (2)
- Posted by Robert Craig <robert_craig at COMPUSERVE.COM> Mar 10, 1997
- 1197 views
Joseph Martin writes: > printf(1, "%f", real[3]) gives > 6.000000 > BUT when I give this command: > printf(1, "%d", real[3]) I get > 5 as the output. I suspect that real[3] is really 5.99999999999999... "%f" format rounds to 6 decimal places by default. When you use %d format it simply truncates it down to an integer rather than rounding it. Use "%.0f" (that's point *zero*) instead of "%d". You'll get the value displayed as an integer with no decimal places and no decimal point. i.e. you'll see: 6 Regards, Rob Craig Rapid Deployment Software