Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

scientific notation optional leading zeros in the exponent #1212

Open
Bollie15 opened this issue Nov 11, 2024 · 1 comment
Open

scientific notation optional leading zeros in the exponent #1212

Bollie15 opened this issue Nov 11, 2024 · 1 comment

Comments

@Bollie15
Copy link

Both 9e-05 and 9e-5 mean the same thing in scientific notation, as leading zeros in the exponent are optional.

use serde_json::{from_str, json, to_string, Value};

fn main() {
    let json_str = r#"{"a":9e-05}"#;
    let json_val: Value = from_str(json_str).unwrap();
    // println!("{}", to_string(&json_val).unwrap());
    println!("{}", json_val.to_string());
    assert_eq!(
        to_string(&json_val).unwrap(),
        json_str
    );
}
{"a":0.00009}
thread 'main' panicked at src/main.rs:17:5:
assertion `left == right` failed
  left: "{\"a\":0.00009}"
 right: "{\"a\":9e-05}"
[package]
name = "serde_float"
version = "0.1.0"
edition = "2021"

[dependencies]
serde_json = {version = "1.0", features = ["preserve_order"] }
@Bollie15
Copy link
Author

How can I specify a floating point number to output in scientific notation?
"{"a":9e-05}" in, and "{"a":9e-05}" out

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant