printf() abbreviaetd floats

I’ll be the first to admit I’ve never been real good with all the crazy
printf() options. What I’d like to be able to do is to print a float in
the most abbreviaetd format possible. I.E.
200.0 should print as “200.0”, “200.” is even better, “200” is best.
3.0 should print as “3.0”
0.3 should print as “0.3”, “.3” is even better.
0.00007 should print as “0.00007”

Is there a single format pattern that I can use to do this?

Bill Caroselli <qtps@earthlink.net> wrote:

I’ll be the first to admit I’ve never been real good with all the crazy
printf() options. What I’d like to be able to do is to print a float in
the most abbreviaetd format possible. I.E.
200.0 should print as “200.0”, “200.” is even better, “200” is best.
3.0 should print as “3.0”
0.3 should print as “0.3”, “.3” is even better.
0.00007 should print as “0.00007”

Is there a single format pattern that I can use to do this?

%g does most of it – I can’t see a way to get 0.00007 not to go as
7e-04, though. :frowning:

-David

Please follow-up to newsgroup, rather than personal email.
David Gibbs
QNX Training Services
dagibbs@qnx.com

David Gibbs <dagibbs@qnx.com> wrote:
DG > Bill Caroselli <qtps@earthlink.net> wrote:

I’ll be the first to admit I’ve never been real good with all the crazy
printf() options. What I’d like to be able to do is to print a float in
the most abbreviaetd format possible. I.E.
200.0 should print as “200.0”, “200.” is even better, “200” is best.
3.0 should print as “3.0”
0.3 should print as “0.3”, “.3” is even better.
0.00007 should print as “0.00007”

Is there a single format pattern that I can use to do this?

DG > %g does most of it – I can’t see a way to get 0.00007 not to go as
DG > 7e-04, though. :frowning:

Thank you.