decimal.proto 4.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. // Copyright 2021 Google LLC
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. syntax = "proto3";
  15. package google.type;
  16. option cc_enable_arenas = true;
  17. option go_package = "google.golang.org/genproto/googleapis/type/decimal;decimal";
  18. option java_multiple_files = true;
  19. option java_outer_classname = "DecimalProto";
  20. option java_package = "com.google.type";
  21. option objc_class_prefix = "GTP";
  22. // A representation of a decimal value, such as 2.5. Clients may convert values
  23. // into language-native decimal formats, such as Java's [BigDecimal][] or
  24. // Python's [decimal.Decimal][].
  25. //
  26. // [BigDecimal]:
  27. // https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/math/BigDecimal.html
  28. // [decimal.Decimal]: https://docs.python.org/3/library/decimal.html
  29. message Decimal {
  30. // The decimal value, as a string.
  31. //
  32. // The string representation consists of an optional sign, `+` (`U+002B`)
  33. // or `-` (`U+002D`), followed by a sequence of zero or more decimal digits
  34. // ("the integer"), optionally followed by a fraction, optionally followed
  35. // by an exponent.
  36. //
  37. // The fraction consists of a decimal point followed by zero or more decimal
  38. // digits. The string must contain at least one digit in either the integer
  39. // or the fraction. The number formed by the sign, the integer and the
  40. // fraction is referred to as the significand.
  41. //
  42. // The exponent consists of the character `e` (`U+0065`) or `E` (`U+0045`)
  43. // followed by one or more decimal digits.
  44. //
  45. // Services **should** normalize decimal values before storing them by:
  46. //
  47. // - Removing an explicitly-provided `+` sign (`+2.5` -> `2.5`).
  48. // - Replacing a zero-length integer value with `0` (`.5` -> `0.5`).
  49. // - Coercing the exponent character to lower-case (`2.5E8` -> `2.5e8`).
  50. // - Removing an explicitly-provided zero exponent (`2.5e0` -> `2.5`).
  51. //
  52. // Services **may** perform additional normalization based on its own needs
  53. // and the internal decimal implementation selected, such as shifting the
  54. // decimal point and exponent value together (example: `2.5e-1` <-> `0.25`).
  55. // Additionally, services **may** preserve trailing zeroes in the fraction
  56. // to indicate increased precision, but are not required to do so.
  57. //
  58. // Note that only the `.` character is supported to divide the integer
  59. // and the fraction; `,` **should not** be supported regardless of locale.
  60. // Additionally, thousand separators **should not** be supported. If a
  61. // service does support them, values **must** be normalized.
  62. //
  63. // The ENBF grammar is:
  64. //
  65. // DecimalString =
  66. // [Sign] Significand [Exponent];
  67. //
  68. // Sign = '+' | '-';
  69. //
  70. // Significand =
  71. // Digits ['.'] [Digits] | [Digits] '.' Digits;
  72. //
  73. // Exponent = ('e' | 'E') [Sign] Digits;
  74. //
  75. // Digits = { '0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9' };
  76. //
  77. // Services **should** clearly document the range of supported values, the
  78. // maximum supported precision (total number of digits), and, if applicable,
  79. // the scale (number of digits after the decimal point), as well as how it
  80. // behaves when receiving out-of-bounds values.
  81. //
  82. // Services **may** choose to accept values passed as input even when the
  83. // value has a higher precision or scale than the service supports, and
  84. // **should** round the value to fit the supported scale. Alternatively, the
  85. // service **may** error with `400 Bad Request` (`INVALID_ARGUMENT` in gRPC)
  86. // if precision would be lost.
  87. //
  88. // Services **should** error with `400 Bad Request` (`INVALID_ARGUMENT` in
  89. // gRPC) if the service receives a value outside of the supported range.
  90. string value = 1;
  91. }