Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

Document unit-test / theory-data impact of .NET 11 double→decimal conversion

オープン 初心者向け
#56,487 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

@SkyDevLab がすでに取り組んでいます。

2026年10月21日 から。

  • #56516 @SkyDevLab による — オープン

評価

難易度
1/5
見積もり時間
1〜3時間
初心者へのやさしさ
88/100
issue の種類
ドキュメント
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
csharp
領域
documentation

調査の方向性

まず docs/core/compatibility/core-libraries/11/decimal-biginteger-floating-point-conversions.md を確認し、既存の Recommended action セクションを確認してください。関連する .NET 11 のライブラリページは docs/core/whats-new/dotnet-11/libraries.md です。issue に記載された xUnit と NUnit のガイダンスおよび例を含む、単体テストへの影響についての簡潔なサブセクションを追加してください。ページで浮動小数点数のテストデータが decimal に変換される方法を説明し、decimal を保持する代替方法を示せば完了です。

索引モデルが issue の本文から書いたものです。

説明

:watch: Not Triaged dotnet-fundamentals/svc
Type of issue
  • Content issue (typos, broken links, missing/outdated content)
  • Product issue (bug in docs tooling/platform)
Location
Description

The breaking-change page correctly documents that float/double → decimal is now correctly rounded (exact binary value), and recommends decimal literals (1.23m) instead of casting double literals.

What is easy to miss in migration: unit-test theory / inline data often injects floating literals as double, then binds or casts them to decimal parameters. That path was “quietly OK” on .NET 10 (15-digit-style conversion) and fails equality / validation on .NET 11 even when production code already uses decimal end-to-end.

xUnit
// Compiles: 0.1 is a double attribute argument
[Theory]
[InlineData(0.1)]
public void Rate(decimal rate)
{
    // Under .NET 10: rate often equals 0.1m
    // Under .NET 11: rate == 0.1000000000000000055511151231m  → assert fails
    Assert.Equal(0.1m, rate);
}

// Does NOT compile: decimal is not a valid C# attribute argument type
// [InlineData(0.1m)]

Workaround that keeps real decimals: MemberData / ClassData / TheoryData<decimal> with 0.1m values (not attribute args).

NUnit
// Non-m literals become double, then convert to decimal param
[TestCase(0.1)]
public void Rate(decimal rate) { ... }

// Prefer:
[TestCase("0.1")]
public void Rate(decimal rate) { ... } // parsed as decimal
Why document this on the BC page
  • The failure mode is often tests only, so teams can think production is broken when CI is.
  • It is not obvious that InlineData(0.1) + decimal is a double conversion (C# forbids 0.1m in attributes).
  • Same BC already says “don’t assume a binary FP literal and a decimal literal with the same source text represent the same value” — a short “Impact on unit tests” subsection with xUnit/NUnit examples would catch a large class of migration failures.
Suggested addition (sketch)

Under Recommended action, add something like:

Unit tests (xUnit / NUnit / similar)
Theory/case attributes cannot take decimal constants in C#. Non-integer numeric attribute args are double/float. Binding those to decimal parameters uses the same conversion as (decimal)double and therefore changes under this BC. Prefer:

  • xUnit: TheoryData / MemberData with decimal values (0.1m), or string data + decimal.Parse
  • NUnit: [TestCase("0.1")] into decimal, or explicit 0.1m only outside attributes
Page URL

https://learn.microsoft.com/en-us/dotnet/core/compatibility/core-libraries/11/decimal-biginteger-floating-point-conversions

Related
  • Runtime BC is intentional; this is a docs request only (no ask to revert conversion).
  • xUnit docs request: https://github.com/xunit/xunit/issues/3658
  • xUnit attribute limitation is language-level (decimal not allowed in attribute arguments).

Related Issues

主要言語
言語のデータがありません
スター
4.8k
フォーク
6.1k
平均マージ
23時間 7分
マージ済み PR(30日)
196

環境構築

Codespaces で開く

このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

dotnet/docs のほかの issue

dotnet/docs の issue をすべて見る

似ている issue

Documentation の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。