Add warning about limited range of decimal encoding (#25294)

Co-authored-by: James Newton-King <james@newtonking.com>
Co-authored-by: Luke Latham <1622880+guardrex@users.noreply.github.com>
pull/25300/head
Martin Liversage 2022-03-11 14:11:26 +01:00 committed by GitHub
parent dc92cec3b5
commit 600a75ea7c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 1 deletions

View File

@ -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. 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] > [!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: Conversion between this type and the BCL `decimal` type might be implemented in C# like this: