nu_protocol/value/
format.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
use std::fmt::Display;

/// A f64 wrapper that formats whole numbers with a decimal point.
pub struct ObviousFloat(pub f64);

impl Display for ObviousFloat {
    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
        let val = self.0;
        // This serialises these as 'nan', 'inf' and '-inf', respectively.
        if val.round() == val && val.is_finite() {
            write!(f, "{}.0", val)
        } else {
            write!(f, "{}", val)
        }
    }
}