Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implicit conversion from float to int #326

Open
JeroenSteen opened this issue Sep 2, 2022 · 1 comment
Open

Implicit conversion from float to int #326

JeroenSteen opened this issue Sep 2, 2022 · 1 comment

Comments

@JeroenSteen
Copy link

JeroenSteen commented Sep 2, 2022

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.

@dvdoug
Copy link
Owner

dvdoug commented Sep 3, 2022

Hi @JeroenSteen

Using ints rather than floats is on purpose, see #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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants