Re: printing double value

From: David White (no_at_email.provided)
Date: 07/29/04


Date: Thu, 29 Jul 2004 13:51:46 +1000


"Arthur J. O'Dwyer" <ajo@nospam.andrew.cmu.edu> wrote in message
news:Pine.LNX.4.60-041.0407282125230.22865@unix40.andrew.cmu.edu...
>
> On Thu, 29 Jul 2004, David White wrote:
> >
> > "tom_usenet" <tom_usenet@hotmail.com> wrote...
> >> The C locale formats doubles with all trailing .0s removed by default.
> >
> > Reasonable, but I don't think it's reasonable that it also omits the
> ^^^
> > decimal point. Without the decimal point the value appears to be an
> > integer (that is, an integer _type_), but I'd rather know that it's
> > a floating-point value that just happens to have zeroes after the
> > decimal point.
>
> Which "I" do you mean? If you're speaking as a programmer,

Yes.

> then you
> really don't have much of a complaint IMHO. If you want the program
> to print some redundant zeros,

I don't.

> then by all means print them! You've
> got the entire iostreams library at your disposal! :)
> If you're speaking as the user of a program written in C++,

Yes as well.

> then
> it's a user-interface design issue, and you ought to speak with the
> programmer (see above paragraph).
>
> Consider that in /some/ contexts, ".0" is /not/ helpful; in fact,

That's not what I want. I want, for example, "5.", not "5". Omitting the '.'
for integer values of floating-point types is inconsistent. If I wanted to
display a list of floating-point values, I'd rather see:
1.47
5.
7.9
than:
1.47
5
7.9

Omitting the '.' for the "5" is a special case that misleads the reader as
to the type of value being displayed.

> it may be misleading. Just ask any high-school chemistry student
> what's the difference between "16 mL" and "16.0 mL"! So it doesn't
> make sense to privilege the "always include a decimal point" style.
>
> I don't know, but I suspect the default behavior is to minimize the
> amount of printing necessary to convey any given value. This default
> behavior benefits those of us who write lazy "debugging printfs"
> and see screens like
>
> % ./myprog test-input
> Running... stage 1 stage 2 3.01 5 5.4 2.99 2.98 4.005 -1 -1.22
> 5.78 -6.9 2 2.3 4 4 4 stage 3 3.01 4.99 5.4 3 2.98 4 -1.01 -1.
> 22 stage 5 stage 6 Done.
>
> only longer. The more information fits on one eighty-column line,
> the better, in this case.
>
> Of course, I could be /wrong/ about the default behavior, but
> do remember that if you want to see "1.0", you know how to get it.

Doing what I want is relatively easy (the format flag 'showpoint'), but that
ought to be the default behaviour. Most programmers won't bother.

DW



Relevant Pages