Skip to content

scientific notation optional leading zeros in the exponent #1212

Open
@Bollie15

Description

@Bollie15

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"] }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions