GithubHelp home page GithubHelp logo

vi / float-pretty-print Goto Github PK

View Code? Open in Web Editor NEW
10.0 5.0 0.0 49 KB

Format f64 in Rust with minimum and maximum width, auto switching between scientific and normal representation

Perl 0.87% Rust 99.13%
rust format human-readable float f64 print string pretty-print

float-pretty-print's People

Contributors

vi avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

float-pretty-print's Issues

Minimum width not correct

Negative exponents seem to miscalculate the minimum width. Example:

format!("= {:6.6}", PrettyPrintFloat(5.0e-50))

results in 5e-50. This is 5 characters wide while the minimum is 6. I am expecting it to print _5e-50 in this case, with the underscore indicating a space for visibility.

inconsistent output when value rounds to zero

These currently pass:

assert_eq!(format!("{:.3}", PrettyPrintFloat(0f64)), "0.0");
assert_eq!(format!("{:.3}", PrettyPrintFloat(0.01f64)), "  0");

But maybe they both should be 0.0? Or at the very least the second one should not be padded to be three characters wide.

Is there a way to prevent rounding?

Hi!

First of all, congratulation on this amazing crate. I'd like to know if there's a way to prevent rounding for big numbers. For instance:

use float_pretty_print::PrettyPrintFloat;

fn main() {
    println!("{}", PrettyPrintFloat(224617.445991228));
}

Prints 2.24617446e5 which, in my case, breaks some tests those expect getting the exact value 224617.445991228.

Could it be possible with your crate?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.