public sealed class Decimal : IMessage<Decimal>, IEquatable<Decimal>, IDeepCloneable<Decimal>, IBufferMessage, IMessage
A representation of a decimal value, such as 2.5. Clients may convert values
into language-native decimal formats, such as Java's [BigDecimal][] or
Python's decimal.Decimal.
The string representation consists of an optional sign, + (U+002B)
or - (U+002D), followed by a sequence of zero or more decimal digits
("the integer"), optionally followed by a fraction, optionally followed
by an exponent.
The fraction consists of a decimal point followed by zero or more decimal
digits. The string must contain at least one digit in either the integer
or the fraction. The number formed by the sign, the integer and the
fraction is referred to as the significand.
The exponent consists of the character e (U+0065) or E (U+0045)
followed by one or more decimal digits.
Services should normalize decimal values before storing them by:
Removing an explicitly-provided + sign (+2.5 -> 2.5).
Replacing a zero-length integer value with 0 (.5 -> 0.5).
Coercing the exponent character to lower-case (2.5E8 -> 2.5e8).
Removing an explicitly-provided zero exponent (2.5e0 -> 2.5).
Services may perform additional normalization based on its own needs
and the internal decimal implementation selected, such as shifting the
decimal point and exponent value together (example: 2.5e-1 <-> 0.25).
Additionally, services may preserve trailing zeroes in the fraction
to indicate increased precision, but are not required to do so.
Note that only the . character is supported to divide the integer
and the fraction; ,should not be supported regardless of locale.
Additionally, thousand separators should not be supported. If a
service does support them, values must be normalized.
Services should clearly document the range of supported values, the
maximum supported precision (total number of digits), and, if applicable,
the scale (number of digits after the decimal point), as well as how it
behaves when receiving out-of-bounds values.
Services may choose to accept values passed as input even when the
value has a higher precision or scale than the service supports, and
should round the value to fit the supported scale. Alternatively, the
service may error with 400 Bad Request (INVALID_ARGUMENT in gRPC)
if precision would be lost.
Services should error with 400 Bad Request (INVALID_ARGUMENT in
gRPC) if the service receives a value outside of the supported range.
public static Decimal FromClrDecimal(decimal value)
Converts the given decimal value to the protobuf Decimal
representation. If the input value naturally contains trailing decimal zeroes (e.g. "1.00")
these are preserved in the protobuf representation.
Converts this protobuf Decimal value to a CLR decimal
value. If the value is within the range of decimal but contains
more than 29 significant digits, the returned value is truncated towards zero.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-08-07 UTC."],[[["\u003cp\u003eThe \u003ccode\u003eDecimal\u003c/code\u003e class represents a decimal value and can be converted to and from language-native decimal formats like Java's \u003ccode\u003eBigDecimal\u003c/code\u003e or Python's \u003ccode\u003edecimal.Decimal\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003eDecimal\u003c/code\u003e class supports various string representations, including optional signs, fractions, and exponents, with specific normalization rules for services to ensure consistency.\u003c/p\u003e\n"],["\u003cp\u003eServices using the \u003ccode\u003eDecimal\u003c/code\u003e class should normalize values, document supported ranges and precision, and handle out-of-bounds or high-precision values appropriately, either by rounding or returning an error.\u003c/p\u003e\n"],["\u003cp\u003eThe class provides methods to convert to and from CLR \u003ccode\u003edecimal\u003c/code\u003e types, including handling of trailing decimal zeroes and potential exceptions like \u003ccode\u003eFormatException\u003c/code\u003e and \u003ccode\u003eOverflowException\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eThe latest version of the library is 2.15.0, with older versions 2.10.0 and 2.2.0 available for use.\u003c/p\u003e\n"]]],[],null,["# Class Decimal (2.17.0)\n\nVersion latestkeyboard_arrow_down\n\n- [2.17.0 (latest)](/dotnet/docs/reference/Google.Api.CommonProtos/latest/Google.Type.Decimal)\n- [2.15.0](/dotnet/docs/reference/Google.Api.CommonProtos/2.15.0/Google.Type.Decimal)\n- [2.10.0](/dotnet/docs/reference/Google.Api.CommonProtos/2.10.0/Google.Type.Decimal)\n- [2.2.0](/dotnet/docs/reference/Google.Api.CommonProtos/2.2.0/Google.Type.Decimal) \n\n public sealed class Decimal : IMessage\u003cDecimal\u003e, IEquatable\u003cDecimal\u003e, IDeepCloneable\u003cDecimal\u003e, IBufferMessage, IMessage\n\nA representation of a decimal value, such as 2.5. Clients may convert values\ninto language-native decimal formats, such as Java's \\[BigDecimal\\]\\[\\] or\nPython's [decimal.Decimal](https://docs.python.org/3/library/decimal.html).\n\n\\[BigDecimal\\]:\n\u003chttps://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/math/BigDecimal.html\u003e \n\nInheritance\n-----------\n\n[object](https://learn.microsoft.com/dotnet/api/system.object) \\\u003e Decimal \n\nImplements\n----------\n\n[IMessage](https://cloud.google.com/dotnet/docs/reference/Google.Protobuf/latest/Google.Protobuf.IMessage-1.html)[Decimal](/dotnet/docs/reference/Google.Api.CommonProtos/latest/Google.Type.Decimal), [IEquatable](https://learn.microsoft.com/dotnet/api/system.iequatable-1)[Decimal](/dotnet/docs/reference/Google.Api.CommonProtos/latest/Google.Type.Decimal), [IDeepCloneable](https://cloud.google.com/dotnet/docs/reference/Google.Protobuf/latest/Google.Protobuf.IDeepCloneable-1.html)[Decimal](/dotnet/docs/reference/Google.Api.CommonProtos/latest/Google.Type.Decimal), [IBufferMessage](https://cloud.google.com/dotnet/docs/reference/Google.Protobuf/latest/Google.Protobuf.IBufferMessage.html), [IMessage](https://cloud.google.com/dotnet/docs/reference/Google.Protobuf/latest/Google.Protobuf.IMessage.html) \n\nInherited Members\n-----------------\n\n[object.Equals(object, object)](https://learn.microsoft.com/dotnet/api/system.object.equals#system-object-equals(system-object-system-object)) \n[object.GetType()](https://learn.microsoft.com/dotnet/api/system.object.gettype) \n[object.ReferenceEquals(object, object)](https://learn.microsoft.com/dotnet/api/system.object.referenceequals)\n\nNamespace\n---------\n\n[Google.Type](/dotnet/docs/reference/Google.Api.CommonProtos/latest/Google.Type)\n\nAssembly\n--------\n\nGoogle.Api.CommonProtos.dll\n\nConstructors\n------------\n\n### Decimal()\n\n public Decimal()\n\n### Decimal(Decimal)\n\n public Decimal(Decimal other)\n\nFields\n------\n\n### ValueFieldNumber\n\n public const int ValueFieldNumber = 1\n\nField number for the \"value\" field.\n\nProperties\n----------\n\n### Descriptor\n\n public static MessageDescriptor Descriptor { get; }\n\n### Parser\n\n public static MessageParser\u003cDecimal\u003e Parser { get; }\n\n### Value\n\n public string Value { get; set; }\n\nThe decimal value, as a string.\n\nThe string representation consists of an optional sign, `+` (`U+002B`)\nor `-` (`U+002D`), followed by a sequence of zero or more decimal digits\n(\"the integer\"), optionally followed by a fraction, optionally followed\nby an exponent.\n\nThe fraction consists of a decimal point followed by zero or more decimal\ndigits. The string must contain at least one digit in either the integer\nor the fraction. The number formed by the sign, the integer and the\nfraction is referred to as the significand.\n\nThe exponent consists of the character `e` (`U+0065`) or `E` (`U+0045`)\nfollowed by one or more decimal digits.\n\nServices **should** normalize decimal values before storing them by:\n\n- Removing an explicitly-provided `+` sign (`+2.5` -\\\u003e `2.5`).\n- Replacing a zero-length integer value with `0` (`.5` -\\\u003e `0.5`).\n- Coercing the exponent character to lower-case (`2.5E8` -\\\u003e `2.5e8`).\n- Removing an explicitly-provided zero exponent (`2.5e0` -\\\u003e `2.5`).\n\nServices **may** perform additional normalization based on its own needs\nand the internal decimal implementation selected, such as shifting the\ndecimal point and exponent value together (example: `2.5e-1` \\\u003c-\\\u003e `0.25`).\nAdditionally, services **may** preserve trailing zeroes in the fraction\nto indicate increased precision, but are not required to do so.\n\nNote that only the `.` character is supported to divide the integer\nand the fraction; `,` **should not** be supported regardless of locale.\nAdditionally, thousand separators **should not** be supported. If a\nservice does support them, values **must** be normalized.\n\nThe ENBF grammar is: \n\n DecimalString =\n [Sign] Significand [Exponent];\n\n Sign = '+' | '-';\n\n Significand =\n Digits ['.'] [Digits] | [Digits] '.' Digits;\n\n Exponent = ('e' | 'E') [Sign] Digits;\n\n Digits = { '0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9' };\n\nServices **should** clearly document the range of supported values, the\nmaximum supported precision (total number of digits), and, if applicable,\nthe scale (number of digits after the decimal point), as well as how it\nbehaves when receiving out-of-bounds values.\n\nServices **may** choose to accept values passed as input even when the\nvalue has a higher precision or scale than the service supports, and\n**should** round the value to fit the supported scale. Alternatively, the\nservice **may** error with `400 Bad Request` (`INVALID_ARGUMENT` in gRPC)\nif precision would be lost.\n\nServices **should** error with `400 Bad Request` (`INVALID_ARGUMENT` in\ngRPC) if the service receives a value outside of the supported range.\n\nMethods\n-------\n\n### CalculateSize()\n\n public int CalculateSize()\n\n### Clone()\n\n public Decimal Clone()\n\n### Equals(Decimal)\n\n public bool Equals(Decimal other)\n\n### Equals(object)\n\n public override bool Equals(object other)\n\n**Overrides** \n[object.Equals(object)](https://learn.microsoft.com/dotnet/api/system.object.equals#system-object-equals(system-object))\n\n### FromClrDecimal(decimal)\n\n public static Decimal FromClrDecimal(decimal value)\n\nConverts the given [decimal](https://learn.microsoft.com/dotnet/api/system.decimal) value to the protobuf [Decimal](/dotnet/docs/reference/Google.Api.CommonProtos/latest/Google.Type.Decimal)\nrepresentation. If the input value naturally contains trailing decimal zeroes (e.g. \"1.00\")\nthese are preserved in the protobuf representation.\n\n### GetHashCode()\n\n public override int GetHashCode()\n\n**Overrides** \n[object.GetHashCode()](https://learn.microsoft.com/dotnet/api/system.object.gethashcode)\n\n### MergeFrom(CodedInputStream)\n\n public void MergeFrom(CodedInputStream input)\n\n### MergeFrom(Decimal)\n\n public void MergeFrom(Decimal other)\n\n### ToClrDecimal()\n\n public decimal ToClrDecimal()\n\nConverts this protobuf [Decimal](/dotnet/docs/reference/Google.Api.CommonProtos/latest/Google.Type.Decimal) value to a CLR [decimal](https://learn.microsoft.com/dotnet/api/system.decimal)\nvalue. If the value is within the range of [decimal](https://learn.microsoft.com/dotnet/api/system.decimal) but contains\nmore than 29 significant digits, the returned value is truncated towards zero.\n\n### ToString()\n\n public override string ToString()\n\n**Overrides** \n[object.ToString()](https://learn.microsoft.com/dotnet/api/system.object.tostring)\n\n### WriteTo(CodedOutputStream)\n\n public void WriteTo(CodedOutputStream output)"]]