forked from xiaopan0513/ord
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdecimal.rs
52 lines (47 loc) Β· 824 Bytes
/
decimal.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
use super::*;
#[derive(PartialEq, Debug)]
pub(crate) struct Decimal {
height: Height,
offset: u64,
}
impl From<Sat> for Decimal {
fn from(sat: Sat) -> Self {
Self {
height: sat.height(),
offset: sat.third(),
}
}
}
impl Display for Decimal {
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
write!(f, "{}.{}", self.height, self.offset)
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn decimal() {
assert_eq!(
Sat(0).decimal(),
Decimal {
height: Height(0),
offset: 0
}
);
assert_eq!(
Sat(1).decimal(),
Decimal {
height: Height(0),
offset: 1
}
);
assert_eq!(
Sat(2099999997689999).decimal(),
Decimal {
height: Height(6929999),
offset: 0
}
);
}
}