Files
nushell/crates/nu-json/Cargo.toml
Bahex 5478ec44bb to <format>: preserve round float numbers' type (#16016)
- fixes #16011

# Description
`Display` implementation for `f64` omits the decimal part for round
numbers, and by using it we did the same.
This affected:
- conversions to delimited formats: `csv`, `tsv`
- textual formats: `html`, `md`, `text`
- pretty printed `json` (`--raw` was unaffected)
- how single float values are displayed in the REPL

> [!TIP]
> This PR fixes our existing json pretty printing implementation.
> We can likely switch to using serde_json's impl using its
PrettyFormatter which allows arbitrary indent strings.

# User-Facing Changes
- Round trips through `csv`, `tsv`, and `json` preserve the type of
round floats.
- It's always clear whether a number is an integer or a float in the
REPL
  ```nushell
  4 / 2
  # => 2  # before: is this an int or a float?

  4 / 2
  # => 2.0  # after: clearly a float
  ``` 

# Tests + Formatting
Adjusted tests for the new behavior.

- 🟢 toolkit fmt
- 🟢 toolkit clippy
- 🟢 toolkit test
- 🟢 toolkit test stdlib

# After Submitting
N/A

---------

Co-authored-by: Bahex <17417311+Bahex@users.noreply.github.com>
2025-06-26 15:15:19 -05:00

39 lines
1.0 KiB
TOML

[package]
authors = [
"The Nushell Project Developers",
"Christian Zangl <laktak@cdak.net>",
]
description = "Fork of serde-hjson"
repository = "https://github.com/nushell/nushell/tree/main/crates/nu-json"
edition = "2024"
license = "MIT"
name = "nu-json"
version = "0.105.2"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[lib]
bench = false
[features]
preserve_order = ["linked-hash-map", "linked-hash-map/serde_impl"]
default = ["preserve_order"]
[dependencies]
linked-hash-map = { version = "0.5", optional = true }
num-traits = { workspace = true }
serde = { workspace = true }
serde_json = { workspace = true }
nu-utils = { path = "../nu-utils", version = "0.105.2", default-features = false }
[dev-dependencies]
nu-test-support = { path = "../nu-test-support", version = "0.105.2" }
nu-path = { path = "../nu-path", version = "0.105.2" }
serde_json = "1.0"
fancy-regex = "0.14.0"
pretty_assertions = { workspace = true }
rstest = { workspace = true, default-features = false }
[lints]
workspace = true