Ticket #275 (closed defect: fixed)

Opened 9 months ago

Last modified 3 months ago

twoDigitFloat bug for 568.80

Reported by: pedrobelo@gmail.com Assigned to: cederberg@gmail.com
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

03/30/08 10:32:12 changed by cederberg@gmail.com

  • owner changed from somebody to cederberg@gmail.com.
  • 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.

03/30/08 11:29:29 changed by cederberg@gmail.com

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.

04/19/08 09:30:25 changed by cederberg@gmail.com

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

Fixed in svn trunk for MochiKit 1.4.