pub struct Float(_, _);Expand description
Human readable float.
Takes a floating point number as input and returns a ready-to-print!() Float.
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(f2.to_f64());
println!("{}\n{}\n{}", f2, f6, f9);
// 3.00
// 3.000000
// 3.000000000Exceptions
| Exceptions | String Output |
|—————————————––|—————––|
| f64::NAN | NaN
| f64::INFINITY & f64::NEG_INFINITY | ∞
To disable checks for these, (you are sure you don’t have NaN’s), enable the ignore_nan_inf feature flag.
Examples
| Input | 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 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<'de> Deserialize<'de> for Float
impl<'de> Deserialize<'de> for Float
source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where __D: Deserializer<'de>,
source§impl PartialEq<&str> for Float
impl PartialEq<&str> for Float
source§impl PartialEq<Float> for Float
impl PartialEq<Float> for Float
source§impl PartialEq<Float> for f64
impl PartialEq<Float> for f64
source§impl PartialEq<Float> for str
impl PartialEq<Float> for str
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 moreimpl StructuralPartialEq for Float
Auto Trait Implementations§
impl RefUnwindSafe for Float
impl Send for Float
impl Sync for Float
impl Unpin for Float
impl UnwindSafe for Float
Blanket Implementations§
source§impl<T> ToCompactString for Twhere
T: Display,
impl<T> ToCompactString for Twhere T: Display,
source§fn to_compact_string(&self) -> CompactString
fn to_compact_string(&self) -> CompactString
CompactString. Read more