-
Notifications
You must be signed in to change notification settings - Fork 5
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
Prices and percentages in entities #217
Comments
My prosal can be found in the commit comments. We should take into account that amounts are stored in different ways now: These will have to be fixed in an update script. |
How are you going to fix this? Store everything x10,000? |
Either that, or make it configurable. The latter is perhaps the best option, as it means we don't need any schema updates or update script for the database: class Amount
{
private $amount;
public function getFloat($times = 4)
{
return $this->amount / pow(10, $times);
}
public function setFloat($value, $times = 4)
{
$this->amount = (int) ($value * pow(10, $times));
return $this;
}
}
// usage:
class MyEntity
{
private $myValue;
public function getMyValue()
{
return $this->myValue->getFloat(2);
}
public function setMyValue($value)
{
$this->myValue->setFloat($value, 2);
return $this;
}
} |
I implemented a first version of this with an example (963db5b) But I'm not yet convinced of the functions in the entity itself. Would it be better to return the amount object itself? Now I have a |
I would hide the fact that we're using the |
So like it is now but with the update of the |
I'll take a more detailed look tomorrow before deciding whether I'm completely happy with the current implementation 😉 |
The implementation with |
I've made some changes to the proposed code. |
I will work further on this with the latest changes of dev-form (otherwise we would get a merge headache) |
See comment dc5550f
The text was updated successfully, but these errors were encountered: