Ticket #275 (closed defect: fixed)

Opened 21 months ago

Last modified 15 months ago

twoDigitFloat bug for 568.80

Reported by: pedrobelo@… Owned by: cederberg@…
Priority: normal Milestone: MochiKit 1.4
Component: component1 Version:
Severity: normal Keywords:
Cc:

Description

twoDigitFloat(568.80) returns "568.79". Just tested in the trunk, too.

In case anyone wants to test this, in test/test_Format.js:

    t.is( twoDigitFloat(568.80), "568.80", "twoDigitFloat 568.80 correct");

Change History

Changed 15 months ago by cederberg@…

  • owner changed from somebody to cederberg@…
  • status changed from new to assigned
  • milestone set to MochiKit 1.4

Indeed. Thanks for the great test case. I'll look into this asap.

Changed 15 months ago by cederberg@…

This test also fails:

    t.is( truncToFixed(568.80, 2), "568.80", "truncToFixed 568.80, floating-point error" );

The problem is that 568.80 * 100 becomes 56879.99999999999 in both Safari 3.1 and Firefox 2.0 (the only two I've tested with). Floating-point number commonly show these types of issues, since they use a binary representation instead of the decimal one that we commonly use.

That said, we should probably handle this is some way. Probably avoid multiplications altogether, since they are bound to increase any rounding errors in the internal representation.

Changed 15 months ago by cederberg@…

  • status changed from assigned to closed
  • resolution set to fixed

Fixed in svn trunk for MochiKit 1.4.

Note: See TracTickets for help on using tickets.