origin icon indicating copy to clipboard operation
origin copied to clipboard

Float array elements are sometimes converted to integers

Open MartinNowak opened this issue 11 years ago • 3 comments

[30.0, 27.2, -2.0].mongoize returns [30, 27.2, -2.0] and [30.0, 27.2, -2.0].mongoize.map{|e| e.class} returns [Fixnum, Float, Fixnum]

MartinNowak avatar Jan 14 '15 18:01 MartinNowak

I found this while storing geo coordinates using a Mongoid model. Some of the coordinates are now Integers while others are Floats.

Apparently it's done deliberately (see here and here), but it makes no sense to convert floats to integers, just because the fractional part is zero.

MartinNowak avatar Jan 14 '15 19:01 MartinNowak

I think this was added to fix another issue, see https://github.com/mongoid/origin/commit/701a8f777c6e9c6d8ca14657e07a6128407ef828

So when you have "2." it would convert to 2... but 2.0 should be a Float IMO.

@MartinNowak want try to fix this and send a PR? thanks

arthurnn avatar Jan 31 '15 05:01 arthurnn

Sure will do.

MartinNowak avatar Jan 31 '15 23:01 MartinNowak