Re: 8.5 beta and decimal precision handling




keithv wrote:
On Sep 28, 3:24 am, Arjen Markus <arjen.mar...@xxxxxxxxxx> wrote:
On 27 sep, 21:22, keithv <kvet...@xxxxxxxxx> wrote:



I just decided to try 8.5 beta on Windows and see how
it works with some of my software.

I found that tip #132 "Revised floating-point
conversions in Tcl" is causing problems.
Specifically, floating point numbers are
being displayed with much more precision than
the user expects. To wit:

pack [label .l -textvariable foo]
set foo [expr {2.7 + 0.6}]
==> label shows up as 3.3000000000000003

I was wondering how people are handling this.

I guess I could set tcl_precision back to 12, but the tip
says that doing so is deprecated.

Thanks,
Keith

There are very good reasons for the change (shimmering
can no longer influence the value), but as Michael
suggests, to mitigate the above effect, you should
use [format] (and perhaps traces).

Yuck, that seems like a step backwards.

Aren't you basically saying that -textvariable is useless
for real number fields? (Once you've got the trace, just
config the widget instead of using a shadow variable.)

Personally, in 10+ years of tcl programming, I've never
encountered the problem tip 132 is fixing, but now in just
one of my applications I have over 100 widgets I must hack up.

Basically your just lucky to have not to do much I18n otherwise you
might have
had the need for format earlier already.

e.g. in germany you would format 12.0 as 12,0 so directly using the
textvariable isn't an option
anyway if you want to support locale specific conventions for this
kind of stuff.

Michael

.



Relevant Pages

  • Re: 8.5 beta and decimal precision handling
    ... conversions in Tcl" is causing problems. ... use (and perhaps traces). ... config the widget instead of using a shadow variable.) ... Personally, in 10+ years of tcl programming, I've never ...
    (comp.lang.tcl)
  • Re: 8.5 beta and decimal precision handling
    ... conversions in Tcl" is causing problems. ... use (and perhaps traces). ... config the widget instead of using a shadow variable.) ... Personally, in 10+ years of tcl programming, I've never ...
    (comp.lang.tcl)
  • Re: C++/Tcl/C++ Interface
    ... retrieve them in a convenient format. ... strings written by Tcl, which is nearly trivial if you stay away from ... This isn't "diving into the guts of Tcl", it is using the Tcl API in the ... script you write a procedure dumping the entire graph, ...
    (comp.lang.tcl)
  • Re: Format output
    ... > direction that may be a shortcut to my learning. ... Tcl seem to take the ... > some specific number of fractional digits to appear, ... Format is the answer and yes, it is a bit cryptic if one does not know ...
    (comp.lang.tcl)
  • Re: "round" - improvement suggestion
    ... I just noticed that XML Schema 1.1 how has a precisionDecimal type. ... a long list of these, including several for rounding, one for integers ... pseudocode into real Tcl code. ... For this we have format. ...
    (comp.lang.tcl)