Pass formatter parameters to WKT writer#200
Conversation
I think that approach will work (1.0 - 0.07) == 0.9299999999999999... percent of the time. 😉 |
|
Dumb jokes aside, you mean something like this, right? I think that should work 100 percent of the time, though opens us up to loss of precision at high values. I don't know why, but I'm sort of surprised that a formatting option like this doesn't already exist. |
Yeah. That's how I ended up implementing it in geoarrow: https://github.com/geoarrow/geoarrow-rs/blob/667389b2a1cdae704b815b6a447505027d876ff9/src/io/display/scalar.rs#L18-L21
Hmm yeah that's true. I'm not sure how to truncate floats with high precision.
You mean in core rust? Maybe it does; I haven't searched for it. |
fn main() {
let num = 3.14159;
let decimals = 3;
let formatted = format!("{:.1$}", num, decimals);
println!("{}", formatted); // Output: 3.142
} |
|
@frewsxcv that's what I'm doing here: But we'd still need a way for the user to pass down the precision desired |
This is just a prototype of #199.
Based on the example here, this optionally passes down a
precisionparameter to theformat!()call.One thing I noticed when I hard-coded
format!("{x:.3} {y:.3}")is that setting that forces even integers to have 3 decimal points. E.g.Potentially this means what I actually want to do to solve my goal in #199 is to truncate the precision of my data, and that will automatically get printed as I want...