pub struct Float(_, _);Expand description
Human readable float.
Takes a floating point number as input and returns a ready-to-print!() Float.
The inner fields are (f64, String) but they are not public.
The default From implementation will print 3 decimal numbers.
This can be changed by using different functions when initially
creating the Float, or converting an existing Float, for example:
let f2 = Float::new_2_point(3.0);
let f6 = Float::new_6_point(3.0);
let f9 = Float::new_9_point(f3.to_f64);
println!("{}\n{}\n{}", f3, f6, f9);
> 3.000
> 3.000000
> 3.000000000All conversions take into account:
and will produce the output:
NaN∞-∞
To disable these checks, (you are sure you don’t have NaN’s), enable the ignore_nan_inf feature flag.
Examples
| Input | String Output |
|––––––––––|—————––|
| 0.0 | 0.000
| 1234.571 | 1,234.571
| 1234.571 | 1,234.571000
| 99.123 (percent) | 99.12%
| 0.001 (percent) | 0%
Implementations§
source§impl Float
impl Float
sourcepub fn inf() -> Self
pub fn inf() -> Self
Returns a Self with the f64 value of f64::INFINITY.
The String is set to ∞.
sourcepub fn neg_inf() -> Self
pub fn neg_inf() -> Self
Returns a Self with the f64 value of f64::INFINITY.
The String is set to -∞.
sourcepub fn percent(f: f64) -> Self
pub fn percent(f: f64) -> Self
Truncates to 2 floating point and appends a %.
Anything lower than 0.01 is rounded down to 0.00.
Examples
| Input | String Output |
|---|---|
| 0.0 | 0.00% |
| 0.001 | 0.00% |
| 0.01 | 0.01% |
| 0.1 | 0.10% |
| 1.0 | 1.00% |
| 50.0 | 50.00% |
| 100.0 | 100.00% |
| 150.0 | 150.00% |
| 1000.0 | 1,000.00% |
| 250000.0 | 250,000.00% |
sourcepub fn into_string(self) -> String
pub fn into_string(self) -> String
Consumes [Self], returning the inner String.
sourcepub fn new_0_point(f: f64) -> Self
pub fn new_0_point(f: f64) -> Self
Same as Self::from but with no floating point on the inner String.
The inner f64 stays the same as the input.
This does not round up or down, it completely ignores the floating point.
Examples
| Input | String Output |
|---|---|
| 0.0 | 0 |
| 50.123 | 50 |
| 100.1 | 100 |
sourcepub fn new_1_point(f: f64) -> Self
pub fn new_1_point(f: f64) -> Self
Create a new Self but with 1 floating point.
sourcepub fn new_2_point(f: f64) -> Self
pub fn new_2_point(f: f64) -> Self
Create a new Self but with 2 floating point.
sourcepub fn new_4_point(f: f64) -> Self
pub fn new_4_point(f: f64) -> Self
Create a new Self but with 4 floating point.
sourcepub fn new_5_point(f: f64) -> Self
pub fn new_5_point(f: f64) -> Self
Create a new Self but with 5 floating point.
sourcepub fn new_6_point(f: f64) -> Self
pub fn new_6_point(f: f64) -> Self
Create a new Self but with 6 floating point.
sourcepub fn new_7_point(f: f64) -> Self
pub fn new_7_point(f: f64) -> Self
Create a new Self but with 7 floating point.
sourcepub fn new_8_point(f: f64) -> Self
pub fn new_8_point(f: f64) -> Self
Create a new Self but with 8 floating point.
sourcepub fn new_9_point(f: f64) -> Self
pub fn new_9_point(f: f64) -> Self
Create a new Self but with 9 floating point.
sourcepub fn new_10_point(f: f64) -> Self
pub fn new_10_point(f: f64) -> Self
Create a new Self but with 10 floating point.
sourcepub fn new_11_point(f: f64) -> Self
pub fn new_11_point(f: f64) -> Self
Create a new Self but with 11 floating point.
sourcepub fn new_12_point(f: f64) -> Self
pub fn new_12_point(f: f64) -> Self
Create a new Self but with 12 floating point.
sourcepub fn new_13_point(f: f64) -> Self
pub fn new_13_point(f: f64) -> Self
Create a new Self but with 13 floating point.
sourcepub fn new_14_point(f: f64) -> Self
pub fn new_14_point(f: f64) -> Self
Create a new Self but with 14 floating point.
sourcepub fn percent_0_point(f: f64) -> Self
pub fn percent_0_point(f: f64) -> Self
Same as Self::percent but with no floating point on the inner String.
The inner f64 stays the same as the input.
This does not round up or down, it completely ignores the floating point.
Examples
| Input | String Output |
|---|---|
| 0.0 | 0% |
| 50.123 | 50% |
| 100.1 | 100% |
sourcepub fn percent_1_point(f: f64) -> Self
pub fn percent_1_point(f: f64) -> Self
Same as Self::percent but with 1 floating point.
sourcepub fn percent_2_point(f: f64) -> Self
pub fn percent_2_point(f: f64) -> Self
Same as Self::percent but with 2 floating point.
sourcepub fn percent_4_point(f: f64) -> Self
pub fn percent_4_point(f: f64) -> Self
Same as Self::percent but with 4 floating point.
Trait Implementations§
source§impl PartialEq<Float> for Float
impl PartialEq<Float> for Float
source§impl PartialOrd<Float> for Float
impl PartialOrd<Float> for Float
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self and other) and is used by the <=
operator. Read more