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

A tip for specifying precision of displayed quantities. #460

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

mateuszbaran
Copy link

I've spent about half an hour figuring it out so I think this tip may be useful for other people 🙂 .

I've spent about half an hour figuring it out so I think this tip may be useful for other people 🙂 .
@sostock
Copy link
Collaborator

sostock commented Jul 7, 2021

I think the wording here is misleading: round does not “set precision of displayed value”. The round function does not display anything by itself, it returns a rounded value. Describing this as specifying precision for display sounds like it is some equivalent to printf formatting.

I think it would be good to add a section about rounding. In that section, we could explain why it is necessary to specify the output unit (or is it obvious enough?).

Note that you can also specify a unit instead of a type as first argument. We should document this as well:

julia> round(typeof(d), d; sigdigits=3)
1.74 mm

julia> round(u"mm", d; sigdigits=3)
1.74 mm

julia> round(u"m", d; sigdigits=3)
0.00174 m

@mateuszbaran
Copy link
Author

"set precision of displayed value" is the thing I wanted to do, so to me this is the key part that needs documenting. If you thing this should be done differently than using round, I'm open to suggestions.

@mateuszbaran
Copy link
Author

mateuszbaran commented Jul 7, 2021

I had a quantity that, when printed it to a string, it gave me way too many digits, more than the precision with which the quantity was determined. So it looked silly and I wanted to trim it -- and it's definitely not obvious how it should be done.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants