-
Notifications
You must be signed in to change notification settings - Fork 50
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
(Issue #10) num_rational::Ratio: Add the ability to format as a decimal #37
Conversation
…approximation to the fmt if it's given a Formatter with precision.
Hi, thanks for the PR! Some of your new Maybe we can do it as a new method instead? Something like I also worry that multiplying 10^n is going to be really prone to overflow, but we can think more deeply about that once the API is sorted out. |
Thank you very much for your feedback. |
…he separate method 'as_decimal' returning String.
I was unable to sit with that issue before now, but here's silly separation of my code to the new |
+ FromPrimitive | ||
+ Integer | ||
+ Pow<usize, Output = T> | ||
+ Signed |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do you need Signed
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm pretty sure that I've added it to be able to use fn abs(&self)
.
Couldn't find a way to drop it now.
src/lib.rs
Outdated
+ Integer | ||
+ Pow<usize, Output = T> | ||
+ Signed | ||
+ std::string::ToString, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is implied by Display
.
(via impl<T> ToString for T where T: Display
)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got rid of it from the type traits, but needed to add use std::string::ToString;
elsewhere to make it compile.
Closing this PR as it's pretty much stagnant at this point. |
Added simple formatting of Ratio as a decimal approximation to the fmt if it's given a Formatter with precision.
After is compiled and passed some new tests for formatting with precision in Formatter I've run the file through the
cargo fmt
before the commit.As it's my first contribution in rust - I'm open for suggestions of improvements.