BoxPacker icon indicating copy to clipboard operation
BoxPacker copied to clipboard

Implicit conversion from float to int

Open JeroenSteen opened this issue 3 years ago • 1 comments

For my use case I want to know which box is the best for shipping of a certain amount of business-cards, and also what the total weight is.

I create a box with the following: $packer->addBox(new TestBox('Verzenddoos bruin+klep 180x115x28mm golf', 196, 120, 31, 31, 180, 115, 28, 400));

Then I add a item of an business cards in a quantity of 1000. $packer->addItem(new TestItem('Visitekaart 85x51mm sulfaatkarton', 85, 51, 0.345, 1.3, true), 1000); // item, quantity

And then I notice these errors:

Deprecated: Implicit conversion from float 0.345 to int loses precision in D:\laragon3\www\..\vendor\dvdoug\boxpacker\tests\Test\TestItem.php on line 65

Deprecated: Implicit conversion from float 1.3 to int loses precision in D:\laragon3\www\..\vendor\dvdoug\boxpacker\tests\Test\TestItem.php on line 65

In the constructor of TestItem the properties width, $length, $depth, and $weight are integers. So that should be the cause. Is their a plan for BoxPacker to allow floats? Or is their a other way to handle this?

Edit: I think maybe instead of using mm, maybe just use micron or microgram. A quantity of 1000 is rather slow, maybe bigger numbers makes it slower.

JeroenSteen avatar Sep 02 '22 14:09 JeroenSteen

Hi @JeroenSteen

Using ints rather than floats is on purpose, see https://github.com/dvdoug/BoxPacker/issues/215 for an example of why. Having said that, I have to admit that shipping something literally as thin as a business card was not something I'd considered.

For your use case, I think multiplying the fractional mm by e.g. 10 or 100 as you already have is probably the easiest option, although (and this might not be suitable), if you only sell cards in e.g. quantities of 100, then maybe your "item" for the purposes of BoxPacker could be a stack of 100 cards, 34 or 35mm deep?

dvdoug avatar Sep 03 '22 15:09 dvdoug