rink_core/output/
numeric_parts.rs1use crate::types::Numeric;
2use serde_derive::Serialize;
3
4#[derive(Debug, Clone, Copy, PartialEq, Serialize)]
7pub enum Digits {
8 Default,
9 FullInt,
10 Digits(u64),
11 Fraction,
12 Scientific,
13 Engineering,
14}
15
16#[derive(Debug, Clone, Serialize)]
17#[serde(rename_all = "camelCase")]
18pub struct NumericParts {
19 numer: String,
20 denom: String,
21 exact_value: Option<String>,
22 approx_value: Option<String>,
23}
24
25impl From<Numeric> for NumericParts {
26 fn from(value: Numeric) -> NumericParts {
27 let (exact, approx) = value.string_repr(10, Digits::Default);
28 let (num, den) = value.to_rational();
29 NumericParts {
30 numer: num.to_string(),
31 denom: den.to_string(),
32 exact_value: exact,
33 approx_value: approx,
34 }
35 }
36}