Why won't THIS work? (2)

new topic     » goto parent     » topic index » view thread      » older message » newer message

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

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu