brick / money

A money and currency library for PHP
MIT License
1.61k stars 96 forks source link

RoundingMode::AUTO? #18

Closed MikeDaniel18 closed 6 years ago

MikeDaniel18 commented 6 years ago

Hi,

First off, I love this library, it's super intuitive and powerful.

One thing I have a problem with, however, is the rounding mode. Why isn't there an option to round to the nearest subunit (context sensitive of course)? It seems odd that I have to hardcode a RoundingMode or do the calculation myself.

For instance, your readme demostrates Rounding as such, where you're required to round either up or down:

$money->plus('0.999', RoundingMode::DOWN); // USD 50.99

$money->minus('0.999', RoundingMode::UP); // USD 49.01

To me, unless you have a specific use case where you need to deliberately favour a particular rounding, under no circumstance would '0.999' ever be considered '0.99'.

Perhaps I am missing something, and if so I'd appreciate the pointer in the right direction.

Cheers, Mike

BenMorel commented 6 years ago

Hi, you have many rounding modes to choose from, not only UP and DOWN!

What you're looking for is most probably RoundingMode::HALF_UP or HALF_EVEN.

There is no such thing as "auto" rounding: the aim of this library is to always return exact results, unless you're explicitly instructing it not to; the default rounding mode is therefore RoundingMode::UNNECESSARY, which will throw an exception if the result cannot be exactly represented at the current scale!

MikeDaniel18 commented 6 years ago

And there I was, missing quite a lot. Case closed. Thank you very much, Benjamin, for highlighting my oversight.

Cheers, Mike

On 9 May 2018, at 22:47, Benjamin Morel notifications@github.com wrote:

Hi, you have many rounding modes to choose from, not only UP and DOWN!

What you're looking for is most probably RoundingMode::HALF_UP or HALF_EVEN.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or mute the thread.