JuliaPhysics / JuliaPhysics/Unitful.jl

how to control the string-formatted precision?

Open
#474 6 comments 8 reactions 0 assignees View on GitHub
Dominant language
Julia
Stars
675
Forks
124
Avg merge
3h 38m
Merged PRs (30d)
1

Description

Feature Request:
Since Unitful produces strings, I frequently want to control the precision to avoid
```
a = (1/7)u"mm"
@printf( "%s", a)
> 0.14285714285714285 mm
```
workaround:
```
a = (1/7)u"mm"
@printf( "%s", round(typeof(a), a, digits=3))
> 0.143 mm
```
Rather than trying to mess with the Base.show() functionality, I think an explicit Unitful-to-string function, possibly taking the printf formatting arguments, would be great.

Also, this overload on round() isn't mentioned in the docs, [source](https://github.com/PainterQubits/Unitful.jl/blob/cc3adef8e4cd72f6f8951cca29f9a8d19a24e5cb/src/quantities.jl#L332) with [kwargs from round](https://docs.julialang.org/en/v1/base/math/#Base.round-Tuple{Type,%20Any})

Thanks

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.