[PD] why does PD round numbers? (in tables, in messageboxes, etc)

Hans-Christoph Steiner hans at at.or.at
Mon Apr 9 02:45:28 CEST 2012

On Apr 8, 2012, at 3:17 PM, katja wrote:

> On Sun, Apr 8, 2012 at 8:43 PM, Hans-Christoph Steiner <hans at at.or.at> wrote:
>> The main reason why this is still like this is because no one has written better code, then done thorough testing in order to prove that the new code doesn't break anything.  People have written better code for this before, no one has done the thorough testing part...
> Hans, can you point to such code, is there still something available
> somewhere? I may be able to test it using the testtools templates.
> Such code could be a very useful precision improvement, even though
> it's not the same as double precision.

Hmm, can't think of any off hand, but its not too hard.  My thought would be to sprintf("%.06f"), then strip off trailing zeros and decimal points.  The rounding stuff is harder, but I am not sure that the current sprintf("%g") handles the rounding any differently:

(from man 3 printf)
     gG      The double argument is converted in style f or e (or F or E for G
             conversions).  The precision specifies the number of significant
             digits.  If the precision is missing, 6 digits are given; if the
             precision is zero, it is treated as 1.  Style e is used if the expo-
             nent from its conversion is less than -4 or greater than or equal to
             the precision.  Trailing zeros are removed from the fractional part
             of the result; a decimal point appears only if it is followed by at
             least one digit.



I have the audacity to believe that peoples everywhere can have three meals a day for their bodies, education and culture for their minds, and dignity, equality and freedom for their spirits.      - Martin Luther King, Jr.

More information about the Pd-list mailing list