settings_ui: Fix IEEE 754 floating point error when serializing value to JSON (#40677)

Closes #40556

Release Notes:

- settings-ui: Fixed an issue where modifying floating point number fields could result in the values written to the settings file containing IEEE 754 floating point error

> [!Note]
> Seems like there's another pull request fixing the centered layout in
#40661 by normalizing the whole `settings.json` file when updating it.
Not sure which is the better way to handle this issue.

## Description

This pull request solves the IEEE 754 floating point error when
serializing values from settings-ui into `settings.json` by creating a
two `serde_helper` to convert the problematic f32 into a formatted two
decimal placed f32.

Fields currently exists the IEEE 754 error:
- Appearance → Unnecessary Code Fade
- Editor → Drop Size Target
- Window & Layout → Centered Layout Left/Right Padding
- Window & Layout → Inactive Opacity

## How to verify

### Unnecessary Code Fade

As Is | To Be
--- | ---
<video
src="https://github.com/user-attachments/assets/1bf4bad2-63c5-4b03-ac29-8b6b59569e16"
/> | <video
src="https://github.com/user-attachments/assets/dadcd4a1-651b-43dd-913f-edae073ceb68"
/>

### Drop Size Target

As Is | To Be
--- | ---
<video
src="https://github.com/user-attachments/assets/9d5b4173-fcac-44d0-b7fc-772a2e426ef1"
/> | <video
src="https://github.com/user-attachments/assets/4b5adeaf-e678-494d-bd1b-6c1d55824c43"
/>

### Centered Layout Left/Right Padding

As Is | To Be
--- | ---
<video
src="https://github.com/user-attachments/assets/33b4e1ff-7ab2-44f7-9e9b-8abad1565d9a"
/> | <video
src="https://github.com/user-attachments/assets/63d8de9e-28d1-4bd7-a6c9-02452e105486"
/>

### Inactive Opacity

As Is | To Be
--- | ---
<video
src="https://github.com/user-attachments/assets/a7fe2e72-deb6-41dc-82f3-e2649503b8a4"
/> | <video
src="https://github.com/user-attachments/assets/993c314f-b6f6-4dcd-8f74-fa357ab063e9"
/>

---------

Co-authored-by: Ben Kunkle <ben@zed.dev>
This commit is contained in:
Dong
2025-10-21 16:45:40 +00:00
committed by GitHub
co-authored by Ben Kunkle
parent fa550de922
commit 641ae90cd6
9 changed files with 181 additions and 5 deletions
@@ -46,6 +46,7 @@ pub struct AnthropicAvailableModel {
/// Configuration of Anthropic's caching API.
pub cache_configuration: Option<LanguageModelCacheConfiguration>,
pub max_output_tokens: Option<u64>,
#[serde(serialize_with = "crate::serialize_optional_f32_with_two_decimal_places")]
pub default_temperature: Option<f32>,
#[serde(default)]
pub extra_beta_headers: Vec<String>,
@@ -71,6 +72,7 @@ pub struct BedrockAvailableModel {
pub max_tokens: u64,
pub cache_configuration: Option<LanguageModelCacheConfiguration>,
pub max_output_tokens: Option<u64>,
#[serde(serialize_with = "crate::serialize_optional_f32_with_two_decimal_places")]
pub default_temperature: Option<f32>,
pub mode: Option<ModelMode>,
}
@@ -332,6 +334,7 @@ pub struct ZedDotDevAvailableModel {
/// Indicates whether this custom model supports caching.
pub cache_configuration: Option<LanguageModelCacheConfiguration>,
/// The default temperature to use for this model.
#[serde(serialize_with = "crate::serialize_optional_f32_with_two_decimal_places")]
pub default_temperature: Option<f32>,
/// Any extra beta headers to provide when using the model.
#[serde(default)]