Struct pretty_dtoa::FmtFloatConfig[][src]

pub struct FmtFloatConfig {
Show fields pub max_sig_digits: Option<u8>, pub min_sig_digits: Option<u8>, pub max_decimal_digits: Option<i8>, pub min_decimal_digits: Option<i8>, pub upper_e_break: i8, pub lower_e_break: i8, pub ignore_extremes: Option<u8>, pub round_mode: RoundMode, pub force_e_notation: bool, pub force_no_e_notation: bool, pub capitalize_e: bool, pub add_point_zero: bool, pub max_width: Option<u8>, pub radix_point: char,
}

Configuration for formatting floats into strings. Look at the associated methods for this type to see default values and specific examples.

Example

use pretty_dtoa::{dtoa, FmtFloatConfig};

let config = FmtFloatConfig::default()
    .round()
    .max_significant_digits(5);

assert_eq!(dtoa(123.4567, config), "123.46");

Fields

max_sig_digits: Option<u8>

A max number of significant digits to include in the formatted string (after the first non-zero digit). None means include all digits

min_sig_digits: Option<u8>

A min number of significant digits to include in the formatted string (after the first non-zero digit). None means no minimum

max_decimal_digits: Option<i8>

A max number of digits after the decimal point to include.

min_decimal_digits: Option<i8>

A min number of digits after the decimal point to include.

upper_e_break: i8

How many digits left of the decimal point there can be using scientific notation

lower_e_break: i8

Lower equivelent of upper_e_break

ignore_extremes: Option<u8>

Ignore digits after (and including) a certain number of consecutive 9’s or 0’s

round_mode: RoundMode

Round or truncate

force_e_notation: bool

Force scientific e notation

force_no_e_notation: bool

Force no scientific e notation. Overrides force_e_notation

capitalize_e: bool

Capitalize the e in scientific notation

add_point_zero: bool

Add a .0 at the end of integers

max_width: Option<u8>

The maximum number of characters in the string. This should be greater than or equal to 7 to guarantee all floats will print correctly, but can be smaller for certain floats

radix_point: char

The seperator between the integer and non-integer part

Implementations

impl FmtFloatConfig[src]

pub const fn default() -> Self[src]

A default configuration. This will always round-trip, so using str::parse::<f64> or str::parse:<f32> will give the exact same float.

pub const fn max_significant_digits(self, val: u8) -> Self[src]

The maximum number of non-zero digits to include in the string

pub const fn min_significant_digits(self, val: u8) -> Self[src]

The minimum number of non-zero digits to include in the string

pub const fn max_decimal_digits(self, val: i8) -> Self[src]

The maximum number of digits past the decimal point to include in the string

pub const fn min_decimal_digits(self, val: i8) -> Self[src]

The minimum number of digits past the decimal point to include in the string

pub const fn upper_e_break(self, val: i8) -> Self[src]

The upper exponent value that will force using exponent notation (default: 4)

pub const fn lower_e_break(self, val: i8) -> Self[src]

The lower exponent value that will force using exponent notation (default: -4)

pub const fn ignore_extremes(self, limit: u8) -> Self[src]

Ignore digits after and including a certain number of consecutive 9’s or 0’s. This is useful for printing numbers with floating point errors to humans, even if the numbers are technically slightly adjusted. (example: 3.5999951 -> 3.6)

pub const fn truncate(self) -> Self[src]

When cutting off after a certain number of significant digits, ignore any further digits. Opposite of round(self).

pub const fn round(self) -> Self[src]

When cutting off after a certain number of significant digits / decimal digits, read the next digit and round up / down. This is the default, but it doesn’t matter in the default config, since no rounding happens.

pub const fn force_e_notation(self) -> Self[src]

Force all floats to be in scientific notation. (example: 31 -> 3.1e1)

pub const fn force_no_e_notation(self) -> Self[src]

Force all floats to not be in scientific notation. (example: 3e10 -> 30000000000)

pub const fn capitalize_e(self, val: bool) -> Self[src]

Capitalize the e in e notation. (example: 3.1e10 -> 3.1E10) (default: false)

pub const fn add_point_zero(self, val: bool) -> Self[src]

Add a “.0” at the end of integers. (example: 31 -> 31.0) (default: true)

pub const fn max_width(self, val: u8) -> Self[src]

The maximum width of all the characters in the string. This should be greater than or equal to 7 to guarantee all floats will print correctly, but can be smaller for certain floats. Floats that are impossible to represent in a certain width will be represented by pound signs.

pub const fn no_max_width(self) -> Self[src]

Allows any width of strings. This is set by default

pub const fn radix_point(self, val: char) -> Self[src]

The seperator between the integer and non-integer part of the float string (default: '.')

Trait Implementations

impl Clone for FmtFloatConfig[src]

impl Copy for FmtFloatConfig[src]

impl Debug for FmtFloatConfig[src]

impl Eq for FmtFloatConfig[src]

impl Hash for FmtFloatConfig[src]

impl PartialEq<FmtFloatConfig> for FmtFloatConfig[src]

impl StructuralEq for FmtFloatConfig[src]

impl StructuralPartialEq for FmtFloatConfig[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.