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

Add new option: round_option (floor/ceil/normal) #9

Open
Sadrak opened this issue Feb 1, 2016 · 4 comments
Open

Add new option: round_option (floor/ceil/normal) #9

Sadrak opened this issue Feb 1, 2016 · 4 comments

Comments

@Sadrak
Copy link
Contributor

Sadrak commented Feb 1, 2016

Hello,

is this feature desired?

https://rt.cpan.org/Public/Bug/Display.html?id=75657

I can make a valid push request against 1.75.

@billward
Copy link
Owner

billward commented Feb 3, 2017

Yeah I think this would be fine, please make a pull request here for it.
Instead of the complicated nesting ternary operators (?:) it would be easier to read if it was done with if/elsif/else, I think. How about replacing the line that calls int() with such a construct?

@Sadrak
Copy link
Contributor Author

Sadrak commented Feb 3, 2017

I have since writing the patch worked with this and after a while i figured out i have a "missunterstanding" of rounding :-/

Rounding should only change the behavior of 0.5 .
Rounding 0.49 always give 0 and 0.51 always give 1.

My intension is a floor/ceil/round with precision ... so i can decide that 0.32 will change to 0.4 or 0.3 ...

That is what my patch do, but i guess the naming is bad ... that is not really a roundoption, it is a floor/ceil/round with precision option.

Please check my submitted tests and feel free to rename roundoption to something better.

I use this with Template::Toolkit to always floor the results of some money calculations in €.

@billward
Copy link
Owner

billward commented Feb 3, 2017

Come to think, there's two more possibilities as well - absolute value based floor/ceil. It would be the same as regular floor/ceil for positive numbers, but the opposite for negative ones. I don't know if anyone would want that though ....

Sadrak added a commit to Sadrak/number-format-perl that referenced this issue Feb 3, 2017
Sadrak added a commit to Sadrak/number-format-perl that referenced this issue Mar 7, 2017
- floor(), abs_floor(), ceil() and abs_ceil() added
- roundoption integrated as fifth argument to format_number()
- see billward#9
@Sadrak
Copy link
Contributor Author

Sadrak commented Mar 7, 2017

ok, i think the logic is ready, there is only a little lack of documentation :-/

number_format() fifth argument must be documented
floor(), abs_floor(), ceil(), abs_ceil() must be documented
roundoption should be better explained

perhaps constants for roundoption values would be better

also i have to switch two rows in format_number() (first round(), than use abs() ; all test pass, i guess the order was not important)

Please have a look and guide me with the documentation (or better: add them ;) )

Sadrak added a commit to Sadrak/number-format-perl that referenced this issue Mar 7, 2017
Sadrak added a commit to Sadrak/number-format-perl that referenced this issue Mar 7, 2017
Sadrak added a commit to Sadrak/number-format-perl that referenced this issue Mar 7, 2017
- to export all constants use :constants or :all
- see billward#9
Sadrak added a commit to Sadrak/number-format-perl that referenced this issue Mar 7, 2017
Sadrak added a commit to Sadrak/number-format-perl that referenced this issue Mar 7, 2017
- Documentation changes
 - explain undef as argument to round() and format_number()
- see billward#9
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