From 600a75ea7c9a2c3ecbef81d80fb5c5d0936dc75f Mon Sep 17 00:00:00 2001 From: Martin Liversage Date: Fri, 11 Mar 2022 14:11:26 +0100 Subject: [PATCH] Add warning about limited range of decimal encoding (#25294) Co-authored-by: James Newton-King Co-authored-by: Luke Latham <1622880+guardrex@users.noreply.github.com> --- aspnetcore/grpc/protobuf.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/aspnetcore/grpc/protobuf.md b/aspnetcore/grpc/protobuf.md index 771704471b..7be3ee38cd 100644 --- a/aspnetcore/grpc/protobuf.md +++ b/aspnetcore/grpc/protobuf.md @@ -198,7 +198,11 @@ message DecimalValue { The `nanos` field represents values from `0.999_999_999` to `-0.999_999_999`. For example, the `decimal` value `1.5m` would be represented as `{ units = 1, nanos = 500_000_000 }`. This is why the `nanos` field in this example uses the `sfixed32` type, which encodes more efficiently than `int32` for larger values. If the `units` field is negative, the `nanos` field should also be negative. > [!NOTE] -> There are multiple other algorithms for encoding `decimal` values as byte strings, but this message is easier to understand than any of them. The values are not affected by big-endian or little-endian on different platforms. +> Additional algorithms are available for encoding `decimal` values as byte strings. The algorithm used by `DecimalValue`: +> +> * Is easy to understand. +> * Isn't affected by big-endian or little-endian on different platforms. +> * Supports decimal numbers ranging from positive `9,223,372,036,854,775,807.999999999` to negative `9,223,372,036,854,775,808.999999999` with a maximum precision of nine decimal places, which isn't the full range of a `decimal`. Conversion between this type and the BCL `decimal` type might be implemented in C# like this: