Auto incrementing by 0.1 results in a full length float

Auto incrementing by 0.1 results in a full length float

morrbomorrbo Posts: 13Questions: 5Answers: 0

Hey there,

When using the auto-incrementing number function in autofill and keytable, if you pass it, for example 0.1, then subsequent values will have the full length of decimal places.

E.g.

1.1 dragged with an increment of 0.1 becomes:
1.2000000000000002
1.3000000000000003

and so on.

Fiddle here:

https://jsfiddle.net/rk2n8up4/2/

I'm not sure if this is a bug per se, or something you expect to be addressed by the datatables dev in a custom algo of some description?

Thanks very much

This question has an accepted answers - jump to answer

Answers

  • sandysandy Posts: 913Questions: 0Answers: 236
    Answer ✓

    Hi morrbo,

    This is expected due to javascript using the IEE 754 standard. You will need to implement some kind of rounding function specific to your needs. This video explains it well.

    Cheers,
    Sandy

This discussion has been closed.