Skip to content

fix: Use decimal literals for tax rate and coordinates - #242

Merged
howaskew merged 1 commit into
masterfrom
fix/decimal-literals
Nov 20, 2026
Merged

howaskew merged 1 commit into
masterfrom
fix/decimal-literals

Conversation

@howaskew

Copy link
Copy Markdown
Contributor

The OpenActive Test Suite has failed in random mode since GitHub's ubuntu-22.04 runner image 20261111 (first seen on 18 November). 98 tests fail, all in business-to-business-tax-calculation-net and business-to-consumer-tax-calculation-net. B is rejected with:

TotalPaymentDueMismatchError: totalPaymentDue price in the request (9.348) does not match expected value (9.348000000000000086486373619)

This affects every repo that runs the test suite against this reference implementation, including data-models and data-model-validator.

Cause

The workflow installs SDK 3.1.419, but dotnet build uses the newest SDK already on the runner. On 12 November that was 10.0.403. The new runner image has 11.0.100.

.NET 11 changed double-to-decimal conversion so that it converts the exact binary value: Decimal and BigInteger floating-point conversions are correctly rounded. This applies to constants too:

If a conversion is evaluated as a compile-time constant, a compiler hosted by the .NET 11 SDK or a later SDK can embed the new result in the output assembly when the project is rebuilt, regardless of the project's target framework.

So (decimal?)0.2 now compiles to 0.2000000000000000111. On a price of 7.79, that gives exactly the 9.348000000000000086486373619 in the error.

Change

Replaces the (decimal?) double-literal casts with decimal literals, as Microsoft recommends:

  • The tax rate, (decimal?)0.2 to 0.2M, in SessionStore.cs and FacilityStore.cs, in both the AspNetCore and AspNetFramework examples.
  • The place coordinates in FeedGenerationHelper.cs, for example (decimal?)51.7502 to 51.7502M. These would otherwise appear in the feeds with long values, such as 51.75019999999999953388396534 (the exact binary value, rounded to 28 significant digits).

(decimal)0.5 in FakeBookingSystem.cs is unchanged, because 0.5 is exact in binary.

Testing

  • I built BookingSystem.AspNetCore and BookingSystem.AspNetCore.IdentityServer in Release with SDK 8. Both have 0 errors, and the warnings are identical to master.
  • I couldn't build locally with SDK 11. This PR's test suite run, on the current runner image, is the real check.

Follow-up, not in this PR

Builds will keep using whichever SDK is newest on the runner. Pinning the SDK (a global.json, or the build step in the test suite workflow) would stop runner image updates changing behaviour silently. Building netcoreapp3.1 with SDK 3.1 may need its own changes, so I've left it for a separate PR.

Casting a double literal to decimal, e.g. (decimal?)0.2, gives the exact
binary value when compiled with the .NET 11 SDK, whatever the target
framework. The tax rate became 0.2000000000000000111, so B failed with
TotalPaymentDueMismatchError in the tax-calculation-net tests.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@howaskew
howaskew requested a review from hkir-dev November 20, 2026 09:37
@howaskew
howaskew merged commit d94a8e5 into master Nov 20, 2026
19 of 21 checks passed
@howaskew
howaskew deleted the fix/decimal-literals branch November 20, 2026 12:23
@howaskew

Copy link
Copy Markdown
Contributor Author

A note on the two framework checks that are still queued:

These jobs run the test suite against the .NET Framework example (BookingSystem.AspNetFramework) on runs-on: windows-2019. GitHub retired that runner image on 30 June 2025 (changelog), so the jobs can never start. GitHub will cancel them after 24 hours. They aren't required checks, so they don't block this PR, and they'll do the same on every PR until the workflow changes.

So the .NET Framework example has had no CI coverage since mid-2025. This PR changes its two store files in the same way as the .NET Core ones ((decimal?)0.2 to 0.2M). The change is identical, but it hasn't been built or tested on .NET Framework here.

I'll raise a separate PR or issue to either move these jobs to windows-2022 or remove them, depending on whether the .NET Framework example is still worth maintaining.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants