rwallace
rwallace

Reputation: 33405

Making printf do the right thing with floating point

I'm trying to make printf 'do the right thing' with floating point numbers, i.e.:

%.20g seems to do all that, but there's one more thing I would like to get:

Is there any way to get the fourth criterion without losing any of the first three?

Upvotes: 0

Views: 204

Answers (1)

Hew Wolff
Hew Wolff

Reputation: 1509

It looks like the flag "#" will at least put a period at the end. Try %#.20g.

The # flag is for example documented here: "Used with a, A, e, E, f, F, g or G it forces the written output to contain a decimal point even if no more digits follow. By default, if no digits follow, no decimal point is written."

Upvotes: 0

Related Questions