nu_protocol/value/
format.rs

1use std::fmt::Display;
2
3/// A f64 wrapper that formats whole numbers with a decimal point.
4pub struct ObviousFloat(pub f64);
5
6impl Display for ObviousFloat {
7    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
8        let val = self.0;
9        // This serialises these as 'nan', 'inf' and '-inf', respectively.
10        if val.round() == val && val.is_finite() {
11            write!(f, "{}.0", val)
12        } else {
13            write!(f, "{}", val)
14        }
15    }
16}