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

Reason for absence of __toString #91

Closed
nWidart opened this issue Mar 9, 2015 · 0 comments
Closed

Reason for absence of __toString #91

nWidart opened this issue Mar 9, 2015 · 0 comments

Comments

@nWidart
Copy link

nWidart commented Mar 9, 2015

Hello,

I was wondering if there is a reason that there isn't a __toString method on the Money\Money object ?

Instead of doing in the view :

echo $product->price->getAmount() / 100 . ' ' . $product->price->getCurrency()

We could do :

echo $product->price

With the following __toString method:

public function __toString()
{
    $formatter = new \NumberFormatter('nl_NL', \NumberFormatter::CURRENCY);

    return $formatter->format($this->getAmount() / 100);
}

Thank you,

Update: I see from this issue that this shouldn't be done here apparently. Any recommended way of handling this, which would remove this logic from the view ?

This issue was closed.
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

1 participant