Skip to content

Pretty print floats #3088

Answered by mladedav
0xbentang asked this question in Q&A
Sep 25, 2024 · 1 comments · 1 reply
Discussion options

You must be logged in to vote

It's not the best thing ever, but you can create a struct PrettyFloat(f64) and implement std::fmt::Debug on it so that it uses exactly the format you want.

Then you should be able to info!(x = debug(PrettyFloat(y))); and it'll use your Debug implementation.

You could also do the same thing with Display if you'd prefer.

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@0xbentang
Comment options

Answer selected by 0xbentang
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants