[
  {
    "path": ".github/dependabot.yml",
    "content": "# Set update schedule for GitHub Actions\n# See https://docs.github.com/en/code-security/supply-chain-security/keeping-your-dependencies-updated-automatically/keeping-your-actions-up-to-date-with-dependabot\n\nversion: 2\nupdates:\n\n- package-ecosystem: \"github-actions\"\n  directory: \"/\"\n  schedule:\n    # Check for updates to GitHub Actions every weekday\n    interval: \"weekly\""
  },
  {
    "path": ".github/workflows/dart.yml",
    "content": "# This workflow uses actions that are not certified by GitHub.\n# They are provided by a third-party and are governed by\n# separate terms of service, privacy policy, and support\n# documentation.\n\nname: Dart\n\non:\n  push:\n    branches: [ master ]\n  pull_request:\n    branches: [ master ]\n  schedule:\n    - cron: \"0 0 * * 0\"\n\njobs:\n  build:\n    runs-on: ubuntu-latest\n\n    steps:\n      - uses: actions/checkout@v6\n      - uses: dart-lang/setup-dart@v1\n\n      - name: Install dependencies\n        run: dart pub get\n\n      - name: Verify formatting\n        run: dart format --output=none --set-exit-if-changed .\n\n      - name: Analyze project source\n        run: dart analyze --fatal-warnings --fatal-infos\n\n      - name: Run VM tests\n        run: dart test --platform vm\n      - name: Run Chrome tests\n        run: dart test --platform chrome\n"
  },
  {
    "path": ".gitignore",
    "content": "packages\n.packages\npubspec.lock\n.pub/\n.dart_tool\nbuild/\n"
  },
  {
    "path": "CHANGELOG.md",
    "content": "# 3.2.4 (2025-06-22)\n\n- Fix issue with scale of zero causing problem in addition/substraction with zero.\n\n# 3.2.3 (2025-06-19)\n\n- Fix bad scale value by parsing `0.0` (see [Issue with Decimal.tryParse return value formatting](https://github.com/a14n/dart-decimal/issues/115))\n\n# 3.2.2 (2025-06-15)\n\n- loosen `intl` to `>=0.19.0 <0.21.0` to address [Intl version within flutter_localizations makes version 3.2.1 of decimal impossible to use on Flutter v3.29.3](https://github.com/a14n/dart-decimal/issues/113)\n- Bump `lints` to 5.0.0\n- [Make `Decimal.zero`, `Decimal.one`, and  `Decimal.ten` final](https://github.com/a14n/dart-decimal/pull/114)\n\n# 3.2.1 (2025-01-20)\n\n- [fix: toString() method for values < 0.1](https://github.com/a14n/dart-decimal/pull/111)\n\n# 3.2.0 (2025-01-19)\n\n- Improve performances\n\n# 3.1.0 (2024-11-22)\n\n- Bump `intl` to 0.20.0, `lints` to 5.0.0\n- Bump SDK to 3.3.0 (enables wasm)\n\n# 3.0.2 (2024-06-09)\n\n- Fix #107: avoid exception when formatting decimal with `NumberFormat.compact()`.\n\n# 3.0.1 (2024-06-04)\n\n- Throw `FormatException` on `formatter.parse('NaN')`.\n\n# 3.0.0 (2024-06-02)\n\n- Add `DecimalFormatter` to deal with [intl](https://pub.dev/packages/intl) package. Your can now parse and format decimals.\n- Add a dependency to intl.\n\n# 2.3.3 (2023-07-08)\n\n- [Introduce logical operators to DecimalIntl to support intl 0.18.0](https://github.com/a14n/dart-decimal/pull/98)\n\n# 2.3.2 (2022-12-07)\n\n- Update files according to license.\n\n# 2.3.1 (2022-11-24)\n\n- Update license file to be recognized by pub.dev.\n\n# 2.3.0 (2022-09-07)\n\n- (Breaking change) Fix `Decimal.pow` return type. This method now returns a `Rational` because `3.pow(-1)` (similar to `1/3`) could not be represented as a `Decimal`.\n- Allow `Rational.toDecimal()` customization via its new `toBigInt` parameter.\n\n# 2.2.0 (2022-04-19)\n\n- Fix [toStringAsExponential returned 10.00e+7 instead of 1.00e+8](https://github.com/a14n/dart-decimal/issues/74)\n\n# 2.1.0 (2021-12-22)\n\n- Fix [toStringAsExponential returns INFINITY](https://github.com/a14n/dart-decimal/issues/48) by implementing `toStringAsExponential` without relying on double implementation.\n- Fix issue to have `zero.precision == 1`.\n\n# 2.0.1 (2021-12-20)\n\n- Fix [`toString` issue with negative number between 0 and -1](https://github.com/a14n/dart-decimal/issues/65)\n\n# 2.0.0 (2021-11-29)\n\nThe goal of this version is to have sharper types on the API and to avoid having [Decimal] objects that are not decimal numbers (`1/3` for instance).\n\nIt introduces several breaking changes.\n\n- `~/` now returns a `BigInt`. If you need a `Decimal` you can convert the `BigInt` to `Decimal` with `bigint.toDecimal()`.\n- Removal of `isNaN` getter. It was always returning `false`.\n- Removal of `isInfinite` getter. It was always returning `false`.\n- Removal of `isNegative` getter. You can replace it with `decimal < Decimal.zero`.\n- `inverse`, `/` now return a `Rational`. If you need a `Decimal` you can convert the `Rational` to `Decimal` with `rational.toDecimal(scaleOnInfinitePrecision: xxx)`. If you need to make several computations where inverses or divisions are involved you should make thoses operations on `Rational` type to avoid loosing precision and at the end convert the result back to `Decimal` if you want to display the result in a decimal form.\n\nOther changes:\n\n- `round()`, `floor()`, `ceil()`, `truncate()` now accept an optional `scale` to indicate at which digit the operation should be done.\n- Add `shift` to move the decimal point.\n- Add extension method `hasFinitePrecision` on `Rational` to know if a decimal form of the rational is possible without loosing precision.\n- Add extension method `toDecimal()` on `Rational`.\n- Add extension method `toDecimal()` on `int`.\n- Add extension method `toDecimal()` on `BigInt`.\n\n# 1.5.0 (2021-11-17)\n\n- Support json serialization as String with `Decimal.fromJson`/`Decimal.toJson`.\n\n# 1.4.0 (2021-11-16)\n\n- Add `Decimal.ten`.\n- Add `Decimal.toBigInt`.\n\n# 1.3.0 (2021-07-21)\n\n- Add `Decimal.fromBigInt`.\n\n# 1.2.0 (2021-05-31)\n\n- Add `DecimalIntl` to allow formatting with [intl](https://pub.dev/packages/intl) package.\n\n# 1.1.0 (2021-04-29)\n\n- Allow negative value as exponent of `pow`.\n\n# 1.0.0+1 (2021-03-29)\n\n- Fix typo in the description of the package.\n\n# 1.0.0 (2021-02-25)\n\n- Stable null safety release.\n\n# 1.0.0-nullsafety (2020-11-27)\n\n- Migrate to nullsafety.\n\n# 0.3.5 (2019-09-02)\n\n- [add `Decimal.pow`](https://github.com/a14n/dart-decimal/issues/24).\n\n# 0.3.4 (2019-07-29)\n\n- add `Decimal.zero` and `Decimal.one`.\n- add `Decimal.inverse`.\n\n# 0.3.3 (2019-01-16)\n\n- add `Decimal.tryParse`.\n\n# 0.3.2 (2018-07-24)\n\n- migration to Dart 2.\n\n# v0.3.1 (2018-07-10)\n\n- make `Decimal.parse` a factory constructor.\n\n# v0.3.0 (2018-07-10)\n\n- allow parsing of `1.`\n\n# v0.2.0 (2018-04-15)\n\n- move to Dart SDK 2.0\n\n# v0.1.4 (2017-06-16)\n\n- make package strong clean\n\n# v0.1.3 (2014-10-29)\n\n- add `Decimal.signum`\n- add `Decimal.hasFinitePrecision`\n- add `Decimal.precision`\n- add `Decimal.scale`\n\n# Semantic Version Conventions\n\nhttp://semver.org/\n\n- *Stable*:  All even numbered minor versions are considered API stable:\n  i.e.: v1.0.x, v1.2.x, and so on.\n- *Development*: All odd numbered minor versions are considered API unstable:\n  i.e.: v0.9.x, v1.1.x, and so on.\n"
  },
  {
    "path": "LICENSE",
    "content": "\n                                 Apache License\n                           Version 2.0, January 2004\n                        http://www.apache.org/licenses/\n\n   TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION\n\n   1. Definitions.\n\n      \"License\" shall mean the terms and conditions for use, reproduction,\n      and distribution as defined by Sections 1 through 9 of this document.\n\n      \"Licensor\" shall mean the copyright owner or entity authorized by\n      the copyright owner that is granting the License.\n\n      \"Legal Entity\" shall mean the union of the acting entity and all\n      other entities that control, are controlled by, or are under common\n      control with that entity. For the purposes of this definition,\n      \"control\" means (i) the power, direct or indirect, to cause the\n      direction or management of such entity, whether by contract or\n      otherwise, or (ii) ownership of fifty percent (50%) or more of the\n      outstanding shares, or (iii) beneficial ownership of such entity.\n\n      \"You\" (or \"Your\") shall mean an individual or Legal Entity\n      exercising permissions granted by this License.\n\n      \"Source\" form shall mean the preferred form for making modifications,\n      including but not limited to software source code, documentation\n      source, and configuration files.\n\n      \"Object\" form shall mean any form resulting from mechanical\n      transformation or translation of a Source form, including but\n      not limited to compiled object code, generated documentation,\n      and conversions to other media types.\n\n      \"Work\" shall mean the work of authorship, whether in Source or\n      Object form, made available under the License, as indicated by a\n      copyright notice that is included in or attached to the work\n      (an example is provided in the Appendix below).\n\n      \"Derivative Works\" shall mean any work, whether in Source or Object\n      form, that is based on (or derived from) the Work and for which the\n      editorial revisions, annotations, elaborations, or other modifications\n      represent, as a whole, an original work of authorship. For the purposes\n      of this License, Derivative Works shall not include works that remain\n      separable from, or merely link (or bind by name) to the interfaces of,\n      the Work and Derivative Works thereof.\n\n      \"Contribution\" shall mean any work of authorship, including\n      the original version of the Work and any modifications or additions\n      to that Work or Derivative Works thereof, that is intentionally\n      submitted to Licensor for inclusion in the Work by the copyright owner\n      or by an individual or Legal Entity authorized to submit on behalf of\n      the copyright owner. For the purposes of this definition, \"submitted\"\n      means any form of electronic, verbal, or written communication sent\n      to the Licensor or its representatives, including but not limited to\n      communication on electronic mailing lists, source code control systems,\n      and issue tracking systems that are managed by, or on behalf of, the\n      Licensor for the purpose of discussing and improving the Work, but\n      excluding communication that is conspicuously marked or otherwise\n      designated in writing by the copyright owner as \"Not a Contribution.\"\n\n      \"Contributor\" shall mean Licensor and any individual or Legal Entity\n      on behalf of whom a Contribution has been received by Licensor and\n      subsequently incorporated within the Work.\n\n   2. Grant of Copyright License. Subject to the terms and conditions of\n      this License, each Contributor hereby grants to You a perpetual,\n      worldwide, non-exclusive, no-charge, royalty-free, irrevocable\n      copyright license to reproduce, prepare Derivative Works of,\n      publicly display, publicly perform, sublicense, and distribute the\n      Work and such Derivative Works in Source or Object form.\n\n   3. Grant of Patent License. Subject to the terms and conditions of\n      this License, each Contributor hereby grants to You a perpetual,\n      worldwide, non-exclusive, no-charge, royalty-free, irrevocable\n      (except as stated in this section) patent license to make, have made,\n      use, offer to sell, sell, import, and otherwise transfer the Work,\n      where such license applies only to those patent claims licensable\n      by such Contributor that are necessarily infringed by their\n      Contribution(s) alone or by combination of their Contribution(s)\n      with the Work to which such Contribution(s) was submitted. If You\n      institute patent litigation against any entity (including a\n      cross-claim or counterclaim in a lawsuit) alleging that the Work\n      or a Contribution incorporated within the Work constitutes direct\n      or contributory patent infringement, then any patent licenses\n      granted to You under this License for that Work shall terminate\n      as of the date such litigation is filed.\n\n   4. Redistribution. You may reproduce and distribute copies of the\n      Work or Derivative Works thereof in any medium, with or without\n      modifications, and in Source or Object form, provided that You\n      meet the following conditions:\n\n      (a) You must give any other recipients of the Work or\n          Derivative Works a copy of this License; and\n\n      (b) You must cause any modified files to carry prominent notices\n          stating that You changed the files; and\n\n      (c) You must retain, in the Source form of any Derivative Works\n          that You distribute, all copyright, patent, trademark, and\n          attribution notices from the Source form of the Work,\n          excluding those notices that do not pertain to any part of\n          the Derivative Works; and\n\n      (d) If the Work includes a \"NOTICE\" text file as part of its\n          distribution, then any Derivative Works that You distribute must\n          include a readable copy of the attribution notices contained\n          within such NOTICE file, excluding those notices that do not\n          pertain to any part of the Derivative Works, in at least one\n          of the following places: within a NOTICE text file distributed\n          as part of the Derivative Works; within the Source form or\n          documentation, if provided along with the Derivative Works; or,\n          within a display generated by the Derivative Works, if and\n          wherever such third-party notices normally appear. The contents\n          of the NOTICE file are for informational purposes only and\n          do not modify the License. You may add Your own attribution\n          notices within Derivative Works that You distribute, alongside\n          or as an addendum to the NOTICE text from the Work, provided\n          that such additional attribution notices cannot be construed\n          as modifying the License.\n\n      You may add Your own copyright statement to Your modifications and\n      may provide additional or different license terms and conditions\n      for use, reproduction, or distribution of Your modifications, or\n      for any such Derivative Works as a whole, provided Your use,\n      reproduction, and distribution of the Work otherwise complies with\n      the conditions stated in this License.\n\n   5. Submission of Contributions. Unless You explicitly state otherwise,\n      any Contribution intentionally submitted for inclusion in the Work\n      by You to the Licensor shall be under the terms and conditions of\n      this License, without any additional terms or conditions.\n      Notwithstanding the above, nothing herein shall supersede or modify\n      the terms of any separate license agreement you may have executed\n      with Licensor regarding such Contributions.\n\n   6. Trademarks. This License does not grant permission to use the trade\n      names, trademarks, service marks, or product names of the Licensor,\n      except as required for reasonable and customary use in describing the\n      origin of the Work and reproducing the content of the NOTICE file.\n\n   7. Disclaimer of Warranty. Unless required by applicable law or\n      agreed to in writing, Licensor provides the Work (and each\n      Contributor provides its Contributions) on an \"AS IS\" BASIS,\n      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or\n      implied, including, without limitation, any warranties or conditions\n      of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A\n      PARTICULAR PURPOSE. You are solely responsible for determining the\n      appropriateness of using or redistributing the Work and assume any\n      risks associated with Your exercise of permissions under this License.\n\n   8. Limitation of Liability. In no event and under no legal theory,\n      whether in tort (including negligence), contract, or otherwise,\n      unless required by applicable law (such as deliberate and grossly\n      negligent acts) or agreed to in writing, shall any Contributor be\n      liable to You for damages, including any direct, indirect, special,\n      incidental, or consequential damages of any character arising as a\n      result of this License or out of the use or inability to use the\n      Work (including but not limited to damages for loss of goodwill,\n      work stoppage, computer failure or malfunction, or any and all\n      other commercial damages or losses), even if such Contributor\n      has been advised of the possibility of such damages.\n\n   9. Accepting Warranty or Additional Liability. While redistributing\n      the Work or Derivative Works thereof, You may choose to offer,\n      and charge a fee for, acceptance of support, warranty, indemnity,\n      or other liability obligations and/or rights consistent with this\n      License. However, in accepting such obligations, You may act only\n      on Your own behalf and on Your sole responsibility, not on behalf\n      of any other Contributor, and only if You agree to indemnify,\n      defend, and hold each Contributor harmless for any liability\n      incurred by, or claims asserted against, such Contributor by reason\n      of your accepting any such warranty or additional liability.\n\n   END OF TERMS AND CONDITIONS\n\n   APPENDIX: How to apply the Apache License to your work.\n\n      To apply the Apache License to your work, attach the following\n      boilerplate notice, with the fields enclosed by brackets \"[]\"\n      replaced with your own identifying information. (Don't include\n      the brackets!)  The text should be enclosed in the appropriate\n      comment syntax for the file format. We also recommend that a\n      file or class name and description of purpose be included on the\n      same \"printed page\" as the copyright notice for easier\n      identification within third-party archives.\n\n   Copyright [yyyy] [name of copyright owner]\n\n   Licensed under the Apache License, Version 2.0 (the \"License\");\n   you may not use this file except in compliance with the License.\n   You may obtain a copy of the License at\n\n       http://www.apache.org/licenses/LICENSE-2.0\n\n   Unless required by applicable law or agreed to in writing, software\n   distributed under the License is distributed on an \"AS IS\" BASIS,\n   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n   See the License for the specific language governing permissions and\n   limitations under the License."
  },
  {
    "path": "NOTICE",
    "content": "Copyright 2013 Alexandre Ardhuin\n\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\n    http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License."
  },
  {
    "path": "README.md",
    "content": "# Dart Decimals\n\n[![Build Status](https://github.com/a14n/dart-decimal/actions/workflows/dart.yml/badge.svg)](https://github.com/a14n/dart-decimal/actions/workflows/dart.yml)\n\nThis project enable to make computations on decimal numbers without losing precision like double operations.\n\nFor instance :\n\n```dart\n// with double\nprint(0.2 + 0.1); // displays 0.30000000000000004\n\n// with decimal\nprint(Decimal.parse('0.2') + Decimal.parse('0.1')); // displays 0.3\n```\n\n## Usage\nTo use this library in your code :\n* add a dependency in your `pubspec.yaml` :\n\n```yaml\ndependencies:\n  decimal:\n```\n\n* add import in your `dart` code :\n\n```dart\nimport 'package:decimal/decimal.dart';\n```\n\n* Start computing using `Decimal.parse('1.23')`.\n\n_Hint_ : To make your code shorter you can define a shortcut for Decimal.parse :\n\n```dart\nfinal d = (String s) => Decimal.parse(s);\nd('0.2') + d('0.1'); // => 0.3\n```\n\n## Formatting with intl\n\nYou can use the [intl](https://pub.dev/packages/intl) package to format decimal\nwith `DecimalFormat` from the `package:decimal/intl.dart` library:\n\n```dart\nimport 'package:decimal/decimal.dart';\nimport 'package:decimal/intl.dart';\n\nmain() {\n  var value = Decimal.parse('1234.56');\n  var formatter = DecimalFormatter(NumberFormat.decimalPattern('en-US'));\n  print(formatter.format(value));\n}\n```\n\nTip: you can define an extension to make it more fluent:\n\n```dart\nextension on Decimal {\n  String formatWith(NumberFormat formatter) => formatter.format(DecimalIntl(this));\n}\nmain() {\n  var value = Decimal.parse('1234.56');\n  var formatter = DecimalFormatter(NumberFormat.decimalPattern('en-US'));\n  print(value.formatWith(formatter));\n}\n```\n\nWARNING: For now (2024.05.30) intl doesn't work with `NumberFormat.maximumFractionDigits` greater than 15 on web plateform and 18 otherwise.\n\n## Parsing with intl\n\nYou can use the `NumberFormat` from [intl](https://pub.dev/packages/intl) package to parse formatted decimals\n\n```dart\nvar currencyFormatter = DecimalFormatter(NumberFormat.simpleCurrency(name: 'USD'));\ncurrencyFormatter.parse('\\$3.14'); // => 3.14\n```\n\n## License\nApache 2.0\n"
  },
  {
    "path": "analysis_options.yaml",
    "content": "include: package:lints/recommended.yaml\nanalyzer:\n  language:\n    strict-casts: true\n    strict-inference: true\n    strict-raw-types: true\nlinter:\n  rules:\n    - prefer_single_quotes\n"
  },
  {
    "path": "example/lib/example.dart",
    "content": "import 'package:decimal/decimal.dart';\n\nvoid main() {\n  print(Decimal.parse('0.1') + Decimal.parse('0.2'));\n}\n"
  },
  {
    "path": "example/pubspec.yaml",
    "content": "name: decimal_example\nversion: 0.0.1\ndescription: Example app for the decimal package.\nhomepage: https://github.com/a14n/dart-decimal\nenvironment:\n  sdk: \">=2.12.0 <3.0.0\"\npublish_to: none\n\ndependencies:\n  decimal:\n    path: ../\n"
  },
  {
    "path": "lib/decimal.dart",
    "content": "// Copyright 2013 Alexandre Ardhuin\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n//     http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport 'dart:math';\n\nimport 'package:rational/rational.dart';\n\nfinal _i0 = BigInt.zero;\nfinal _i1 = BigInt.one;\nfinal _i2 = BigInt.two;\nfinal _i5 = BigInt.from(5);\nfinal _i10 = BigInt.from(10);\nfinal _r10 = Rational.fromInt(10);\n\n/// A number that can be exactly written with a finite number of digits in the\n/// decimal system.\nclass Decimal implements Comparable<Decimal> {\n  Decimal._(this._value, this._scale);\n\n  /// Create a new [Decimal] from a [BigInt].\n  factory Decimal.fromBigInt(BigInt value) => Decimal._(value, 0);\n\n  /// Create a new [Decimal] from an [int].\n  factory Decimal.fromInt(int value) => Decimal.fromBigInt(BigInt.from(value));\n\n  /// Create a new [Decimal] from its [String] representation.\n  factory Decimal.fromJson(String value) => Decimal.parse(value);\n\n  final BigInt _value;\n  final int _scale;\n  late final Rational _rational = _scale > 0\n      ? Rational(_value, _i10.pow(_scale))\n      : Rational(_value * _i10.pow(_scale.abs()));\n\n  static final _pattern =\n      RegExp(r'^([+-]?\\d*)(?:\\.(\\d*))?(?:[eE]([+-]?\\d+))?$');\n\n  /// Parses [source] as a decimal literal and returns its value as [Decimal].\n  static Decimal parse(String source) {\n    final match = _pattern.firstMatch(source);\n    if (match == null) {\n      throw FormatException('$source is not a valid format');\n    }\n    final group1 = match.group(1);\n    final group2 = match.group(2) ?? '';\n    final group3 = match.group(3);\n\n    var value = BigInt.parse('$group1$group2');\n    var scale = group3 == null ? 0 : -int.parse(group3);\n    scale += group2.length;\n    return Decimal._(value, scale);\n  }\n\n  /// Parses [source] as a decimal literal and returns its value as [Decimal], or null if the parsing fails.\n  static Decimal? tryParse(String source) {\n    try {\n      return Decimal.parse(source);\n    } on FormatException {\n      return null;\n    }\n  }\n\n  /// The [Decimal] corresponding to `0`.\n  static final zero = Decimal.fromInt(0);\n\n  /// The [Decimal] corresponding to `1`.\n  static final one = Decimal.fromInt(1);\n\n  /// The [Decimal] corresponding to `10`.\n  static final ten = Decimal.fromInt(10);\n\n  /// The [Rational] corresponding to `this`.\n  Rational toRational() => _rational;\n\n  /// Returns `true` if `this` is an integer.\n  bool get isInteger => _scale <= 0 || _rescaled._scale <= 0;\n\n  /// Returns a [Rational] corresponding to `1/this`.\n  Rational get inverse => _rational.inverse;\n\n  @override\n  bool operator ==(Object other) => other is Decimal && compareTo(other) == 0;\n\n  @override\n  int get hashCode => Object.hash(_rescaled._value, _rescaled._scale);\n\n  /// Returns a [String] representation of `this`.\n  @override\n  String toString() {\n    var d = _rescaled;\n    var v = d._value.abs().toString();\n    var s = d._scale;\n    if (s <= 0) {\n      v = v + '0' * -s;\n    } else if (v.length <= s) {\n      v = '0.${'0' * (s - v.length)}$v';\n    } else {\n      v = '${v.substring(0, v.length - s)}.${v.substring(v.length - s)}';\n    }\n    if (_value.isNegative) v = '-$v';\n    return v;\n  }\n\n  /// Converts `this` to [String] by using [toString].\n  String toJson() => toString();\n\n  @override\n  int compareTo(Decimal other) {\n    var (d1, d2) = _unifyScale(this, other);\n    return d1._value.compareTo(d2._value);\n  }\n\n  /// Addition operator.\n  Decimal operator +(Decimal other) {\n    var (d1, d2) = _unifyScale(this, other);\n    return Decimal._(d1._value + d2._value, d1._scale);\n  }\n\n  /// Subtraction operator.\n  Decimal operator -(Decimal other) => this + (-other);\n\n  /// Multiplication operator.\n  Decimal operator *(Decimal other) =>\n      Decimal._(_value * other._value, _scale + other._scale);\n\n  /// Euclidean modulo operator.\n  ///\n  /// See [num.operator%].\n  Decimal operator %(Decimal other) {\n    var (d1, d2) = _unifyScale(this, other);\n    return Decimal._(d1._value % d2._value, d1._scale);\n  }\n\n  /// Division operator.\n  Rational operator /(Decimal other) => _rational / other._rational;\n\n  /// Truncating division operator.\n  ///\n  /// See [num.operator~/].\n  BigInt operator ~/(Decimal other) {\n    var (d1, d2) = _unifyScale(this, other);\n    return d1._value ~/ d2._value;\n  }\n\n  /// Returns the negative value of this rational.\n  Decimal operator -() => Decimal._(-_value, _scale);\n\n  /// Return the remainder from dividing this [Decimal] by [other].\n  Decimal remainder(Decimal other) {\n    var (d1, d2) = _unifyScale(this, other);\n    return Decimal._(d1._value.remainder(d2._value), d1._scale);\n  }\n\n  /// Whether this number is numerically smaller than [other].\n  bool operator <(Decimal other) => compareTo(other) < 0;\n\n  /// Whether this number is numerically smaller than or equal to [other].\n  bool operator <=(Decimal other) => compareTo(other) <= 0;\n\n  /// Whether this number is numerically greater than [other].\n  bool operator >(Decimal other) => compareTo(other) > 0;\n\n  /// Whether this number is numerically greater than or equal to [other].\n  bool operator >=(Decimal other) => compareTo(other) >= 0;\n\n  /// Returns the absolute value of `this`.\n  Decimal abs() => Decimal._(_value.abs(), _scale);\n\n  /// The signum function value of `this`.\n  ///\n  /// E.e. -1, 0 or 1 as the value of this [Decimal] is negative, zero or positive.\n  int get sign => _value.sign;\n\n  @Deprecated('Use .sign')\n  int get signum => _value.sign;\n\n  /// Returns the greatest [Decimal] value no greater than this [Decimal].\n  ///\n  /// An optional [scale] value can be provided as parameter to indicate the\n  /// digit used as reference for the operation.\n  ///\n  /// ```\n  /// var x = Decimal.parse('123.4567');\n  /// x.floor(); // 123\n  /// x.floor(scale: 1); // 123.4\n  /// x.floor(scale: 2); // 123.45\n  /// x.floor(scale: -1); // 120\n  /// ```\n  Decimal floor({int scale = 0}) => _scaleAndApply(scale, (e) => e.floor());\n\n  /// Returns the least [Decimal] value that is no smaller than this [Decimal].\n  ///\n  /// An optional [scale] value can be provided as parameter to indicate the\n  /// digit used as reference for the operation.\n  ///\n  /// ```\n  /// var x = Decimal.parse('123.4567');\n  /// x.ceil(); // 124\n  /// x.ceil(scale: 1); // 123.5\n  /// x.ceil(scale: 2); // 123.46\n  /// x.ceil(scale: -1); // 130\n  /// ```\n  Decimal ceil({int scale = 0}) => _scaleAndApply(scale, (e) => e.ceil());\n\n  /// Returns the [Decimal] value closest to this number.\n  ///\n  /// Rounds away from zero when there is no closest integer:\n  /// `(3.5).round() == 4` and `(-3.5).round() == -4`.\n  ///\n  /// An optional [scale] value can be provided as parameter to indicate the\n  /// digit used as reference for the operation.\n  ///\n  /// ```\n  /// var x = Decimal.parse('123.4567');\n  /// x.round(); // 123\n  /// x.round(scale: 1); // 123.5\n  /// x.round(scale: 2); // 123.46\n  /// x.round(scale: -1); // 120\n  /// ```\n  Decimal round({int scale = 0}) => _scaleAndApply(scale, (e) => e.round());\n\n  Decimal _scaleAndApply(int scale, BigInt Function(Rational) f) {\n    final scaleFactor = ten.pow(scale);\n    return (f(_rational * scaleFactor).toRational() / scaleFactor).toDecimal();\n  }\n\n  /// The [BigInt] obtained by discarding any fractional digits from `this`.\n  Decimal truncate({int scale = 0}) =>\n      _scaleAndApply(scale, (e) => e.truncate());\n\n  /// Shift the decimal point on the right for positive [value] or on the left\n  /// for negative one.\n  ///\n  /// ```dart\n  /// var x = Decimal.parse('123.4567');\n  /// x.shift(1); // 1234.567\n  /// x.shift(-1); // 12.34567\n  /// ```\n  Decimal shift(int value) => Decimal._(_value, _scale - value);\n\n  /// Clamps `this` to be in the range [lowerLimit]-[upperLimit].\n  Decimal clamp(Decimal lowerLimit, Decimal upperLimit) => this < lowerLimit\n      ? lowerLimit\n      : this > upperLimit\n          ? upperLimit\n          : this;\n\n  /// The [BigInt] obtained by discarding any fractional digits from `this`.\n  BigInt toBigInt() => switch (this) {\n        var d when d._scale > 0 => d._value ~/ _i10.pow(d._scale),\n        var d when d._scale < 0 => d._value * _i10.pow(-d._scale),\n        var d => d._value,\n      };\n\n  /// Returns `this` as a [double].\n  ///\n  /// If the number is not representable as a [double], an approximation is\n  /// returned. For numerically large integers, the approximation may be\n  /// infinite.\n  double toDouble() => switch (this) {\n        var d when d._scale > 0 => d._value / _i10.pow(d._scale),\n        var d when d._scale < 0 => (d._value * _i10.pow(-d._scale)).toDouble(),\n        var d => d._value.toDouble(),\n      };\n\n  /// The precision of this [Decimal].\n  ///\n  /// The precision is the number of digits in the unscaled value.\n  ///\n  /// ```dart\n  /// Decimal.parse('0').precision; // => 1\n  /// Decimal.parse('1').precision; // => 1\n  /// Decimal.parse('1.5').precision; // => 2\n  /// Decimal.parse('0.5').precision; // => 2\n  /// ```\n  int get precision {\n    final value = abs();\n    return value.scale + value.toBigInt().toString().length;\n  }\n\n  /// The scale of this [Decimal].\n  ///\n  /// The scale is the number of digits after the decimal point.\n  ///\n  /// ```dart\n  /// Decimal.parse('1.5').scale; // => 1\n  /// Decimal.parse('1').scale; // => 0\n  /// ```\n  int get scale => _scale <= 0 ? 0 : max(_rescaled._scale, 0);\n\n  /// A decimal-point string-representation of this number with [fractionDigits]\n  /// digits after the decimal point.\n  String toStringAsFixed(int fractionDigits) {\n    assert(fractionDigits >= 0);\n    if (fractionDigits == 0) return round().toBigInt().toString();\n    final value = round(scale: fractionDigits);\n    final intPart = value.toBigInt().abs();\n    final decimalPart =\n        (one + value.abs() - intPart.toDecimal()).shift(fractionDigits);\n    return '${value < zero ? '-' : ''}$intPart.${decimalPart.toString().substring(1)}';\n  }\n\n  /// An exponential string-representation of this number with [fractionDigits]\n  /// digits after the decimal point.\n  String toStringAsExponential([int fractionDigits = 0]) {\n    assert(fractionDigits >= 0);\n\n    final negative = this < zero;\n    var value = abs();\n    var eValue = 0;\n    while (value < one && value > zero) {\n      value *= ten;\n      eValue--;\n    }\n    while (value >= ten) {\n      value = (value / ten).toDecimal();\n      eValue++;\n    }\n    value = value.round(scale: fractionDigits);\n    // If the rounded value is 10, then divide it once more to make it follow\n    // the normalized scientific notation. See https://github.com/a14n/dart-decimal/issues/74\n    if (value == ten) {\n      value = (value / ten).toDecimal();\n      eValue++;\n    }\n\n    return <String>[\n      if (negative) '-',\n      value.toStringAsFixed(fractionDigits),\n      'e',\n      if (eValue >= 0) '+',\n      '$eValue',\n    ].join();\n  }\n\n  /// A string representation with [precision] significant digits.\n  String toStringAsPrecision(int precision) {\n    assert(precision > 0);\n\n    if (this == zero) {\n      return <String>[\n        '0',\n        if (precision > 1) '.',\n        for (var i = 1; i < precision; i++) '0',\n      ].join();\n    }\n\n    final limit = ten.pow(precision).toDecimal();\n\n    var shift = one;\n    final absValue = abs();\n    var pad = 0;\n    while (absValue * shift < limit) {\n      pad++;\n      shift *= ten;\n    }\n    while (absValue * shift >= limit) {\n      pad--;\n      shift = (shift / ten).toDecimal();\n    }\n    final value = ((this * shift).round() / shift).toDecimal();\n    return pad <= 0 ? value.toString() : value.toStringAsFixed(pad);\n  }\n\n  /// Returns `this` to the power of [exponent].\n  ///\n  /// Returns [Rational.one] if the [exponent] equals `0`.\n  Rational pow(int exponent) => _rational.pow(exponent);\n\n  static (Decimal, Decimal) _unifyScale(Decimal d1, Decimal d2) {\n    var s1 = d1._scale;\n    var s2 = d2._scale;\n    return switch (null) {\n      _ when s1 > s2 => (d1, Decimal._(d2._value * _i10.pow(s1 - s2), s1)),\n      _ when s1 < s2 => (Decimal._(d1._value * _i10.pow(s2 - s1), s2), d2),\n      _ => (d1, d2),\n    };\n  }\n\n  late final Decimal _rescaled = () {\n    if (this == Decimal.zero) return Decimal.zero;\n    var d = this;\n    while (true) {\n      if (d._value % _i10 == _i0) {\n        d = Decimal._(d._value ~/ _i10, d._scale - 1);\n      } else {\n        break;\n      }\n    }\n    return d;\n  }();\n}\n\n/// Extensions on [Rational].\nextension RationalExt on Rational {\n  /// Returns a [Decimal] corresponding to `this`.\n  ///\n  /// Some rational like `1/3` can not be converted to decimal because they need\n  /// an infinite number of digits. For those cases (where [hasFinitePrecision]\n  /// is `false`) a [scaleOnInfinitePrecision] and a [toBigInt] can be provided\n  /// to convert `this` to a [Decimal] representation. By default [toBigInt]\n  /// use [Rational.truncate] to limit the number of digit.\n  ///\n  /// Note that the returned decimal will not be exactly equal to `this`.\n  Decimal toDecimal({\n    int? scaleOnInfinitePrecision,\n    BigInt Function(Rational)? toBigInt,\n  }) {\n    if (hasFinitePrecision) {\n      var scale = _scale;\n      return Decimal._((this * Rational(_i10.pow(scale))).toBigInt(), scale);\n    }\n    if (scaleOnInfinitePrecision == null) {\n      throw AssertionError(\n          'scaleOnInfinitePrecision is required for rationale without finite precision');\n    }\n    final scaleFactor = _r10.pow(scaleOnInfinitePrecision);\n    toBigInt ??= (value) => value.truncate();\n    return Decimal._(toBigInt(this * scaleFactor), scaleOnInfinitePrecision);\n  }\n\n  /// Returns `true` if this [Rational] has a finite precision.\n  ///\n  /// Having a finite precision means that the number can be exactly represented\n  /// as decimal with a finite number of fractional digits.\n  bool get hasFinitePrecision {\n    // the denominator should only be a product of powers of 2 and 5\n    var den = denominator;\n    while (den % _i5 == _i0) {\n      den = den ~/ _i5;\n    }\n    while (den % _i2 == _i0) {\n      den = den ~/ _i2;\n    }\n    return den == _i1;\n  }\n\n  /// The scale of this [Rational].\n  ///\n  /// The scale is the number of digits after the decimal point.\n  ///\n  /// ```dart\n  /// Decimal.parse('1.5').scale; // => 1\n  /// Decimal.parse('1').scale; // => 0\n  /// ```\n  int get _scale {\n    var i = 0;\n    var x = this;\n    while (!x.isInteger) {\n      i++;\n      x *= _r10;\n    }\n    return i;\n  }\n}\n\n/// Extensions on [BigInt].\nextension BigIntExt on BigInt {\n  /// This [BigInt] as a [Decimal].\n  Decimal toDecimal() => Decimal.fromBigInt(this);\n}\n\n/// Extensions on [int].\nextension IntExt on int {\n  /// This [int] as a [Decimal].\n  Decimal toDecimal() => Decimal.fromInt(this);\n}\n"
  },
  {
    "path": "lib/intl.dart",
    "content": "// Copyright 2013 Alexandre Ardhuin\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n//     http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport 'package:decimal/decimal.dart';\nimport 'package:intl/intl.dart';\nimport 'package:rational/rational.dart';\n\nclass DecimalFormatter {\n  DecimalFormatter(this.numberFormat);\n\n  final NumberFormat numberFormat;\n\n  /// Parses [text] as a decimal literal using the provided number formatter and returns its value as [Decimal]\n  Decimal parse(String text) =>\n      _DartDecimalNumberParser(numberFormat, text).value!;\n\n  /// Parses [text] as a decimal literal using the provided number formatter and returns its value as [Decimal], or null if the parsing fails.\n  Decimal? tryParse(String text) {\n    try {\n      return parse(text);\n    } on FormatException {\n      return null;\n    }\n  }\n\n  /// Format [number] according to our pattern and return the formatted string.\n  String format(Decimal number) => numberFormat.format(_DecimalIntl(number));\n}\n\nclass _DecimalIntl {\n  _DecimalIntl(Decimal decimal) : this._rational(decimal.toRational());\n\n  _DecimalIntl._rational(this._rational);\n\n  factory _DecimalIntl._(dynamic number) {\n    if (number is _DecimalIntl) {\n      return number;\n    } else if (number is Decimal) {\n      return _DecimalIntl(number);\n    } else if (number is Rational) {\n      return _DecimalIntl._rational(number);\n    } else if (number is BigInt) {\n      return _DecimalIntl(Decimal.fromBigInt(number));\n    } else if (number is int) {\n      return _DecimalIntl(Decimal.fromInt(number));\n    }\n    return _DecimalIntl(Decimal.parse(number.toString()));\n  }\n\n  final Rational _rational;\n\n  bool get isNegative => _rational < Rational.zero;\n\n  _DecimalIntl abs() => _DecimalIntl._rational(_rational.abs());\n\n  _DecimalIntl operator ~/(dynamic other) =>\n      _DecimalIntl._(_rational ~/ _DecimalIntl._(other)._rational);\n\n  _DecimalIntl operator +(dynamic other) =>\n      _DecimalIntl._(_rational + _DecimalIntl._(other)._rational);\n\n  _DecimalIntl operator -(dynamic other) =>\n      _DecimalIntl._(_rational - _DecimalIntl._(other)._rational);\n\n  _DecimalIntl operator *(dynamic other) =>\n      _DecimalIntl._(_rational * _DecimalIntl._(other)._rational);\n\n  num operator /(dynamic other) =>\n      (_rational / _DecimalIntl._(other)._rational).toDouble();\n\n  bool operator <(dynamic other) => _rational < _DecimalIntl._(other)._rational;\n\n  bool operator <=(dynamic other) =>\n      _rational <= _DecimalIntl._(other)._rational;\n\n  bool operator >(dynamic other) => _rational > _DecimalIntl._(other)._rational;\n\n  bool operator >=(dynamic other) =>\n      _rational >= _DecimalIntl._(other)._rational;\n\n  _DecimalIntl remainder(dynamic other) =>\n      _DecimalIntl._(_rational.remainder(_DecimalIntl._(other)._rational));\n\n  int toInt() => _rational.toBigInt().toInt();\n\n  double toDouble() => _rational.toDouble();\n\n  _DecimalIntl round() => _DecimalIntl._(_rational.round());\n\n  @override\n  bool operator ==(Object other) =>\n      _rational == _DecimalIntl._(other)._rational;\n\n  @override\n  int get hashCode => _rational.hashCode;\n\n  @override\n  String toString() => _rational.toString();\n}\n\nclass _DartDecimalNumberParser extends NumberParserBase<Decimal> {\n  _DartDecimalNumberParser(super.format, super.text);\n\n  @override\n  Decimal fromNormalized(String normalizedText) =>\n      Decimal.parse(normalizedText);\n\n  @override\n  Decimal nan() => throw FormatException('Could not parse Decimal');\n\n  @override\n  Decimal negativeInfinity() =>\n      throw FormatException('Could not parse Decimal');\n\n  @override\n  Decimal positiveInfinity() =>\n      throw FormatException('Could not parse Decimal');\n\n  @override\n  Decimal scaled(Decimal parsed, int scale) => (parsed / Decimal.fromInt(scale))\n      .toDecimal(scaleOnInfinitePrecision: scale);\n}\n"
  },
  {
    "path": "pubspec.yaml",
    "content": "name: decimal\nversion: 3.2.4\ndescription: >\n  The decimal package allows you to deal with decimal numbers without losing\n  precision.\nrepository: https://github.com/a14n/dart-decimal\nenvironment:\n  sdk: \">=3.3.0 <4.0.0\"\n\ndependencies:\n  intl: \">=0.19.0 <0.21.0\"\n  rational: ^2.0.0\n\ndev_dependencies:\n  expector: ^0.1.4\n  lints: 6.0.0\n  test: ^1.25.4\n"
  },
  {
    "path": "test/decimal_test.dart",
    "content": "// Copyright 2013 Alexandre Ardhuin\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n//     http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport 'dart:convert';\n\nimport 'package:decimal/decimal.dart';\nimport 'package:expector/expector.dart';\nimport 'package:rational/rational.dart';\nimport 'package:test/test.dart' show group, test;\n\nDecimal dec(String value) => Decimal.parse(value);\n\nvoid main() {\n  test('tryParse', () {\n    expectThat(Decimal.tryParse('1')).equals(dec('1'));\n    expectThat(Decimal.tryParse('a')).isNull;\n  });\n  test('string validation', () async {\n    await expectThat(() => dec('1')).returnsNormally();\n    await expectThat(() => dec('-1')).returnsNormally();\n    await expectThat(() => dec('1.')).returnsNormally();\n    await expectThat(() => dec('1.0')).returnsNormally();\n  });\n  test('get isInteger', () {\n    expectThat(dec('1').isInteger).isTrue;\n    expectThat(dec('0').isInteger).isTrue;\n    expectThat(dec('-1').isInteger).isTrue;\n    expectThat(dec('-1.0').isInteger).isTrue;\n    expectThat(dec('1.2').isInteger).isFalse;\n    expectThat(dec('-1.21').isInteger).isFalse;\n    expectThat(dec('1.00000').isInteger).isTrue;\n    expectThat(dec('-1.00000').isInteger).isTrue;\n  });\n  test('get inverse', () {\n    expectThat(dec('1').inverse).equals(dec('1').toRational());\n    expectThat(dec('0.1').inverse).equals(dec('10').toRational());\n    expectThat(dec('200').inverse).equals(dec('0.005').toRational());\n  });\n  test('operator ==(Decimal other)', () {\n    expectThat(dec('1') == dec('1')).isTrue;\n    expectThat(dec('1') == dec('2')).isFalse;\n    expectThat(dec('1') == dec('1.0')).isTrue;\n    expectThat(dec('1') == dec('2.0')).isFalse;\n    expectThat(dec('1') != dec('1')).isFalse;\n    expectThat(dec('1') != dec('2')).isTrue;\n  });\n  test('toString()', () {\n    for (final n in [\n      '0',\n      '1',\n      '-0.1',\n      '-1',\n      '-1.1',\n      '23',\n      '31878018903828899277492024491376690701584023926880.1',\n      '0.05'\n    ]) {\n      expectThat(dec(n).toString()).equals(n);\n    }\n    expectThat(dec('0.000').toString()).equals('0');\n    expectThat(dec('-0.000').toString()).equals('0');\n    expectThat((dec('1.2') - dec('1.2')).toString()).equals('0');\n    expectThat(dec('1.000').toString()).equals('1');\n    expectThat(dec('-1.000').toString()).equals('-1');\n    expectThat((dec('1') / dec('3')).toString()).equals('1/3');\n    expectThat(dec('9.9').toString()).equals('9.9');\n    expectThat((dec('1.0000000000000000000000000000000000000000000000001') *\n                dec('1.0000000000000000000000000000000000000000000000001'))\n            .toString())\n        .equals(\n            '1.00000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000001');\n    expectThat(dec('0.0500').toString()).equals('0.05');\n  });\n  test('compareTo(Decimal other)', () {\n    expectThat(dec('1').compareTo(dec('1'))).equals(0);\n    expectThat(dec('1').compareTo(dec('1.0'))).equals(0);\n    expectThat(dec('1').compareTo(dec('1.1'))).equals(-1);\n    expectThat(dec('1').compareTo(dec('0.9'))).equals(1);\n  });\n  test('operator +(Decimal other)', () {\n    expectThat(dec('1') + dec('1')).equals(dec('2'));\n    expectThat(dec('1.1') + dec('1')).equals(dec('2.1'));\n    expectThat(dec('1.1') + dec('0.9')).equals(dec('2'));\n    expectThat(dec('31878018903828899277492024491376690701584023926880.0') +\n            dec('0.9'))\n        .equals(dec('31878018903828899277492024491376690701584023926880.9'));\n    expectThat(dec('0.000325') + dec('0')).equals(dec('0.000325'));\n    expectThat(dec('0') + dec('0.000325')).equals(dec('0.000325'));\n    expectThat(dec('0.000325') + Decimal.zero).equals(dec('0.000325'));\n    expectThat(Decimal.zero + dec('0.000325')).equals(dec('0.000325'));\n    expectThat(dec('0.000325') + dec('0.0000000000')).equals(dec('0.000325'));\n    expectThat(dec('0.0000000000') + dec('0.000325')).equals(dec('0.000325'));\n  });\n  test('operator -(Decimal other)', () {\n    expectThat(dec('1') - dec('1')).equals(dec('0'));\n    expectThat(dec('1.1') - dec('1')).equals(dec('0.1'));\n    expectThat(dec('0.1') - dec('1.1')).equals(dec('-1'));\n    expectThat(dec('31878018903828899277492024491376690701584023926880.0') -\n            dec('0.9'))\n        .equals(dec('31878018903828899277492024491376690701584023926879.1'));\n  });\n  test('operator *(Decimal other)', () {\n    expectThat(dec('1') * dec('1')).equals(dec('1'));\n    expectThat(dec('1.1') * dec('1')).equals(dec('1.1'));\n    expectThat(dec('1.1') * dec('0.1')).equals(dec('0.11'));\n    expectThat(dec('1.1') * dec('0')).equals(dec('0'));\n    expectThat(dec('31878018903828899277492024491376690701584023926880.0') *\n            dec('10'))\n        .equals(dec('318780189038288992774920244913766907015840239268800'));\n  });\n  test('operator %(Decimal other)', () {\n    expectThat(dec('2') % dec('1')).equals(dec('0'));\n    expectThat(dec('0') % dec('1')).equals(dec('0'));\n    expectThat(dec('8.9') % dec('1.1')).equals(dec('0.1'));\n    expectThat(dec('-1.2') % dec('0.5')).equals(dec('0.3'));\n    expectThat(dec('-1.2') % dec('-0.5')).equals(dec('0.3'));\n    expectThat(dec('1e1') % dec('0.3')).equals(dec('0.1'));\n    expectThat(dec('0.3') % dec('1e1')).equals(dec('0.3'));\n  });\n  test('operator /(Decimal other)', () async {\n    await expectThat(() => dec('1') / dec('0')).throws;\n    expectThat(dec('1') / dec('1')).equals(dec('1').toRational());\n    expectThat(dec('1.1') / dec('1')).equals(dec('1.1').toRational());\n    expectThat(dec('1.1') / dec('0.1')).equals(dec('11').toRational());\n    expectThat(dec('0') / dec('0.2315')).equals(dec('0').toRational());\n    expectThat(dec('31878018903828899277492024491376690701584023926880.0') /\n            dec('10'))\n        .equals(dec('3187801890382889927749202449137669070158402392688')\n            .toRational());\n  });\n  test('operator ~/(Decimal other)', () async {\n    await expectThat(() => dec('1') ~/ dec('0')).throws;\n    expectThat(dec('3') ~/ dec('2')).equals(BigInt.from(1));\n    expectThat(dec('1.1') ~/ dec('1')).equals(BigInt.from(1));\n    expectThat(dec('1.1') ~/ dec('0.1')).equals(BigInt.from(11));\n    expectThat(dec('0') ~/ dec('0.2315')).equals(BigInt.from(0));\n  });\n  test('operator -()', () {\n    expectThat(-dec('1')).equals(dec('-1'));\n    expectThat(-dec('-1')).equals(dec('1'));\n  });\n  test('remainder(Decimal other)', () {\n    expectThat(dec('2').remainder(dec('1'))).equals(dec('0'));\n    expectThat(dec('0').remainder(dec('1'))).equals(dec('0'));\n    expectThat(dec('8.9').remainder(dec('1.1'))).equals(dec('0.1'));\n    expectThat(dec('-1.2').remainder(dec('0.5'))).equals(dec('-0.2'));\n    expectThat(dec('-1.2').remainder(dec('-0.5'))).equals(dec('-0.2'));\n  });\n  test('operator <(Decimal other)', () {\n    expectThat(dec('1') < dec('1')).isFalse;\n    expectThat(dec('1') < dec('1.0')).isFalse;\n    expectThat(dec('1') < dec('1.1')).isTrue;\n    expectThat(dec('1') < dec('0.9')).isFalse;\n  });\n  test('operator <=(Decimal other)', () {\n    expectThat(dec('1') <= dec('1')).isTrue;\n    expectThat(dec('1') <= dec('1.0')).isTrue;\n    expectThat(dec('1') <= dec('1.1')).isTrue;\n    expectThat(dec('1') <= dec('0.9')).isFalse;\n  });\n  test('operator >(Decimal other)', () {\n    expectThat(dec('1') > dec('1')).isFalse;\n    expectThat(dec('1') > dec('1.0')).isFalse;\n    expectThat(dec('1') > dec('1.1')).isFalse;\n    expectThat(dec('1') > dec('0.9')).isTrue;\n  });\n  test('operator >=(Decimal other)', () {\n    expectThat(dec('1') >= dec('1')).isTrue;\n    expectThat(dec('1') >= dec('1.0')).isTrue;\n    expectThat(dec('1') >= dec('1.1')).isFalse;\n    expectThat(dec('1') >= dec('0.9')).isTrue;\n  });\n  test('abs()', () {\n    expectThat(dec('-1.49').abs()).equals(dec('1.49'));\n    expectThat(dec('1.498').abs()).equals(dec('1.498'));\n  });\n  test('signum', () {\n    expectThat(dec('-1.49').sign).equals(-1);\n    expectThat(dec('1.49').sign).equals(1);\n    expectThat(dec('0').sign).equals(0);\n  });\n  group('floor()', () {\n    test('without scale', () {\n      expectThat(dec('1').floor()).equals(dec('1'));\n      expectThat(dec('-1').floor()).equals(dec('-1'));\n      expectThat(dec('1.49').floor()).equals(dec('1'));\n      expectThat(dec('-1.49').floor()).equals(dec('-2'));\n    });\n    test('with positive scale', () {\n      expectThat(dec('1').floor(scale: 1)).equals(dec('1'));\n      expectThat(dec('-1').floor(scale: 1)).equals(dec('-1'));\n      expectThat(dec('1.49').floor(scale: 1)).equals(dec('1.4'));\n      expectThat(dec('-1.49').floor(scale: 1)).equals(dec('-1.5'));\n    });\n    test('with negative scale', () {\n      expectThat(dec('1').floor(scale: -1)).equals(dec('0'));\n      expectThat(dec('-1').floor(scale: -1)).equals(dec('-10'));\n      expectThat(dec('14.9').floor(scale: -1)).equals(dec('10'));\n      expectThat(dec('-14.9').floor(scale: -1)).equals(dec('-20'));\n    });\n  });\n  group('ceil()', () {\n    test('without scale', () {\n      expectThat(dec('1').ceil()).equals(dec('1'));\n      expectThat(dec('-1').ceil()).equals(dec('-1'));\n      expectThat(dec('-1.49').ceil()).equals(dec('-1'));\n      expectThat(dec('1.49').ceil()).equals(dec('2'));\n    });\n    test('with positive scale', () {\n      expectThat(dec('1').ceil(scale: 1)).equals(dec('1'));\n      expectThat(dec('-1').ceil(scale: 1)).equals(dec('-1'));\n      expectThat(dec('-1.49').ceil(scale: 1)).equals(dec('-1.4'));\n      expectThat(dec('1.49').ceil(scale: 1)).equals(dec('1.5'));\n    });\n    test('with negative scale', () {\n      expectThat(dec('1').ceil(scale: -1)).equals(dec('10'));\n      expectThat(dec('-1').ceil(scale: -1)).equals(dec('0'));\n      expectThat(dec('-14.9').ceil(scale: -1)).equals(dec('-10'));\n      expectThat(dec('14.9').ceil(scale: -1)).equals(dec('20'));\n    });\n  });\n  group('round()', () {\n    test('without scale', () {\n      expectThat(dec('1.4999').round()).equals(dec('1'));\n      expectThat(dec('2.5').round()).equals(dec('3'));\n      expectThat(dec('-2.51').round()).equals(dec('-3'));\n      expectThat(dec('-2').round()).equals(dec('-2'));\n    });\n    test('with positive scale', () {\n      expectThat(dec('1.4999').round(scale: 1)).equals(dec('1.5'));\n      expectThat(dec('2.5').round(scale: 1)).equals(dec('2.5'));\n      expectThat(dec('-2.51').round(scale: 1)).equals(dec('-2.5'));\n      expectThat(dec('-2').round(scale: 1)).equals(dec('-2'));\n    });\n    test('with negative scale', () {\n      expectThat(dec('1.4999').round(scale: -1)).equals(dec('0'));\n      expectThat(dec('12.5').round(scale: -1)).equals(dec('10'));\n      expectThat(dec('-25.1').round(scale: -1)).equals(dec('-30'));\n      expectThat(dec('-24').round(scale: -1)).equals(dec('-20'));\n    });\n  });\n  group('truncate()', () {\n    test('without scale', () {\n      expectThat(dec('1.4999').truncate()).equals(dec('1'));\n      expectThat(dec('2.5').truncate()).equals(dec('2'));\n      expectThat(dec('-2.51').truncate()).equals(dec('-2'));\n      expectThat(dec('-2').truncate()).equals(dec('-2'));\n    });\n    test('with positive scale', () {\n      expectThat(dec('1.4999').truncate(scale: 1)).equals(dec('1.4'));\n      expectThat(dec('2.5').truncate(scale: 1)).equals(dec('2.5'));\n      expectThat(dec('-2.51').truncate(scale: 1)).equals(dec('-2.5'));\n      expectThat(dec('-2').truncate(scale: 1)).equals(dec('-2'));\n    });\n    test('with negative scale', () {\n      expectThat(dec('1.4999').truncate(scale: -1)).equals(dec('0'));\n      expectThat(dec('12.5').truncate(scale: -1)).equals(dec('10'));\n      expectThat(dec('-25.1').truncate(scale: -1)).equals(dec('-20'));\n      expectThat(dec('-24').truncate(scale: -1)).equals(dec('-20'));\n    });\n  });\n  test('shift()', () {\n    expectThat(dec('123.4567').shift(0)).equals(dec('123.4567'));\n    expectThat(dec('123.4567').shift(1)).equals(dec('1234.567'));\n    expectThat(dec('123.4567').shift(2)).equals(dec('12345.67'));\n    expectThat(dec('123.4567').shift(6)).equals(dec('123456700'));\n    expectThat(dec('123.4567').shift(-1)).equals(dec('12.34567'));\n    expectThat(dec('123.4567').shift(-2)).equals(dec('1.234567'));\n    expectThat(dec('123.4567').shift(-3)).equals(dec('0.1234567'));\n  });\n  test('clamp(Decimal lowerLimit, Decimal upperLimit)', () {\n    expectThat(dec('2.51').clamp(dec('1'), dec('3'))).equals(dec('2.51'));\n    expectThat(dec('2.51').clamp(dec('2.6'), dec('3'))).equals(dec('2.6'));\n    expectThat(dec('2.51').clamp(dec('1'), dec('2.5'))).equals(dec('2.5'));\n  });\n  test('toBigInt()', () {\n    expectThat(dec('2.51').toBigInt()).equals(BigInt.from(2));\n    expectThat(dec('-2.51').toBigInt()).equals(BigInt.from(-2));\n    expectThat(dec('-2').toBigInt()).equals(BigInt.from(-2));\n  });\n  test('toDouble()', () {\n    expectThat(dec('2.51').toDouble()).equals(2.51);\n    expectThat(dec('-2.51').toDouble()).equals(-2.51);\n    expectThat(dec('-2').toDouble()).equals(-2.0);\n  });\n  test('precision', () {\n    expectThat(dec('100').precision).equals(3);\n    expectThat(dec('10000').precision).equals(5);\n    expectThat(dec('-10000').precision).equals(5);\n    expectThat(dec('1e5').precision).equals(6);\n    expectThat(dec('100.000').precision).equals(3);\n    expectThat(dec('100.1').precision).equals(4);\n    expectThat(dec('100.0000001').precision).equals(10);\n    expectThat(dec('-100.0000001').precision).equals(10);\n    expectThat(dec('100.000000000000000000000000000001').precision).equals(33);\n    expectThat(dec('0').precision).equals(1);\n    expectThat(dec('0.10').precision).equals(2);\n    expectThat(dec('0.00').precision).equals(1);\n    expectThat(dec('0.1').precision).equals(2);\n    expectThat(dec('0.01').precision).equals(3);\n    expectThat(dec('-0.01').precision).equals(3);\n  });\n  test('scale', () {\n    expectThat(dec('100').scale).equals(0);\n    expectThat(dec('10000').scale).equals(0);\n    expectThat(dec('100.000').scale).equals(0);\n    expectThat(dec('100.1').scale).equals(1);\n    expectThat(dec('100.0000001').scale).equals(7);\n    expectThat(dec('-100.0000001').scale).equals(7);\n    expectThat(dec('100.000000000000000000000000000001').scale).equals(30);\n  });\n  test('toStringAsFixed(int fractionDigits)', () {\n    for (final n in [0, 1, 23, 2.2, 2.499999, 2.5, 2.7, 1.235]) {\n      for (final p in [0, 1, 5, 10]) {\n        expectThat(dec(n.toString()).toStringAsFixed(p))\n            .equals(n.toStringAsFixed(p));\n      }\n    }\n    expectThat(dec('19').toStringAsFixed(5)).equals('19.00000');\n  });\n  test('toStringAsExponential(int fractionDigits)', () {\n    expectThat(dec('0').toStringAsExponential(0)).equals('0e+0');\n    for (final n in [0, 1, 23, 2.2, 2.499999, 2.5, 2.7, 1.235, -1.2, -0.02]) {\n      for (final p in [1, 5, 10]) {\n        expectThat(dec(n.toString()).toStringAsExponential(p))\n            .equals(n.toStringAsExponential(p));\n      }\n    }\n    // issue https://github.com/a14n/dart-decimal/issues/48\n    expectThat(dec('1.7976931348623157e+310').toStringAsExponential(10))\n        .equals('1.7976931349e+310');\n    // issue https://github.com/a14n/dart-decimal/issues/74\n    expectThat(dec('9.9999e+7').toStringAsExponential(2)).equals('1.00e+8');\n  });\n  test('toStringAsPrecision(int precision)', () {\n    expectThat(dec('0').toStringAsPrecision(1)).equals('0');\n    expectThat(dec('0').toStringAsPrecision(5)).equals('0.0000');\n    expectThat(dec('0').toStringAsPrecision(10)).equals('0.000000000');\n    expectThat(dec('1').toStringAsPrecision(1)).equals('1');\n    expectThat(dec('1').toStringAsPrecision(5)).equals('1.0000');\n    expectThat(dec('1').toStringAsPrecision(10)).equals('1.000000000');\n    expectThat(dec('23').toStringAsPrecision(1)).equals('20');\n    expectThat(dec('23').toStringAsPrecision(5)).equals('23.000');\n    expectThat(dec('23').toStringAsPrecision(10)).equals('23.00000000');\n    expectThat(dec('2.2').toStringAsPrecision(1)).equals('2');\n    expectThat(dec('2.2').toStringAsPrecision(5)).equals('2.2000');\n    expectThat(dec('2.2').toStringAsPrecision(10)).equals('2.200000000');\n    expectThat(dec('2.499999').toStringAsPrecision(1)).equals('2');\n    expectThat(dec('2.499999').toStringAsPrecision(5)).equals('2.5000');\n    expectThat(dec('2.499999').toStringAsPrecision(10)).equals('2.499999000');\n    expectThat(dec('2.5').toStringAsPrecision(1)).equals('3');\n    expectThat(dec('2.5').toStringAsPrecision(5)).equals('2.5000');\n    expectThat(dec('2.5').toStringAsPrecision(10)).equals('2.500000000');\n    expectThat(dec('2.7').toStringAsPrecision(1)).equals('3');\n    expectThat(dec('2.7').toStringAsPrecision(5)).equals('2.7000');\n    expectThat(dec('2.7').toStringAsPrecision(10)).equals('2.700000000');\n    expectThat(dec('1.235').toStringAsPrecision(1)).equals('1');\n    expectThat(dec('1.235').toStringAsPrecision(5)).equals('1.2350');\n    expectThat(dec('1.235').toStringAsPrecision(10)).equals('1.235000000');\n  });\n  test('issue #13', () {\n    expectThat(Decimal.parse('21.962962546543768').toString())\n        .equals('21.962962546543768');\n  });\n  test('zero', () {\n    expectThat(Decimal.zero).equals(Decimal.fromInt(0));\n  });\n  test('one', () {\n    expectThat(Decimal.one).equals(Decimal.fromInt(1));\n  });\n  test('ten', () {\n    expectThat(Decimal.ten).equals(Decimal.fromInt(10));\n  });\n  test('pow', () {\n    expectThat(dec('100').pow(0)).equals(dec('1').toRational());\n    expectThat(dec('100').pow(1)).equals(dec('100').toRational());\n    expectThat(dec('100').pow(2)).equals(dec('10000').toRational());\n    expectThat(dec('100').pow(-1)).equals(dec('0.01').toRational());\n    expectThat(dec('100').pow(-2)).equals(dec('0.0001').toRational());\n    expectThat(dec('0.1').pow(0)).equals(dec('1').toRational());\n    expectThat(dec('0.1').pow(1)).equals(dec('0.1').toRational());\n    expectThat(dec('0.1').pow(2)).equals(dec('0.01').toRational());\n    expectThat(dec('0.1').pow(-1)).equals(dec('10').toRational());\n    expectThat(dec('0.1').pow(-2)).equals(dec('100').toRational());\n    expectThat(dec('-1').pow(0)).equals(dec('1').toRational());\n    expectThat(dec('-1').pow(1)).equals(dec('-1').toRational());\n    expectThat(dec('-1').pow(2)).equals(dec('1').toRational());\n    expectThat(dec('-1').pow(-1)).equals(dec('-1').toRational());\n    expectThat(dec('-1').pow(-2)).equals(dec('1').toRational());\n  });\n  test('fromJson', () async {\n    expectThat(Decimal.fromJson('1')).equals(Decimal.one);\n    await expectThat(() => Decimal.fromJson('-1')).returnsNormally();\n    await expectThat(() => Decimal.fromJson('1.')).returnsNormally();\n    await expectThat(() => Decimal.fromJson('1.0')).returnsNormally();\n  });\n  test('toJson', () {\n    const encoder = JsonEncoder();\n    expectThat(encoder.convert({\n      'zero': Decimal.zero,\n      'one': Decimal.one,\n    })).equals(\n      '{'\n      '\"zero\":\"${Decimal.zero}\",'\n      '\"one\":\"${Decimal.one}\"'\n      '}',\n    );\n  });\n\n  test('Rational.hasFinitePrecision', () {\n    const p = Rational.parse;\n    for (final r in [\n      p('100'),\n      p('100.100'),\n      p('1') / p('5'),\n      (p('1') / p('3')) * p('3'),\n      p('0.00000000000000000000001'),\n    ]) {\n      expectThat(r.hasFinitePrecision).isTrue;\n    }\n    for (final r in [p('1') / p('3')]) {\n      expectThat(r.hasFinitePrecision).isFalse;\n    }\n  });\n\n  test('Rational.toDecimal', () {\n    Rational r(int numerator, int denominator) =>\n        Rational.fromInt(numerator, denominator);\n    expectThat(r(1, 1).toDecimal()).equals(dec('1'));\n    expectThat(() => r(1, 3).toDecimal()).throwsA<AssertionError>();\n    expectThat(r(1, 3).toDecimal(scaleOnInfinitePrecision: 1))\n        .equals(dec('0.3'));\n    expectThat(r(1, 4).toDecimal(scaleOnInfinitePrecision: 1))\n        .equals(dec('0.25'));\n    expectThat(r(2, 3).toDecimal(\n      scaleOnInfinitePrecision: 1,\n      toBigInt: (v) => v.round(),\n    )).equals(dec('0.7'));\n  });\n}\n"
  },
  {
    "path": "test/intl_test.dart",
    "content": "// Copyright 2013 Alexandre Ardhuin\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n//     http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport 'dart:math';\n\nimport 'package:decimal/decimal.dart';\nimport 'package:decimal/intl.dart';\nimport 'package:expector/expector.dart';\nimport 'package:intl/intl.dart';\nimport 'package:test/test.dart' show group, test;\n\nDecimal dec(String value) => Decimal.parse(value);\n\nvoid main() {\n  group('DecimalFormatter.format', () {\n    test('outputs the same result as with double', () {\n      final formats = <NumberFormat>[\n        NumberFormat.decimalPattern('en-US'),\n        NumberFormat.decimalPattern('fr-FR'),\n      ];\n      final numbers = <String>[\n        '0',\n        '1',\n        '-1.123',\n        '123456789.0123',\n      ];\n      for (var format in formats) {\n        final formatter = DecimalFormatter(format);\n        for (var number in numbers) {\n          expectThat(formatter.format(dec(number)))\n              .equals(format.format(double.parse(number)));\n        }\n      }\n    });\n\n    test('outputs result for long decimal', () {\n      final format = NumberFormat.decimalPattern('en-US');\n      final formatter = DecimalFormatter(format);\n      expectThat(formatter.format(dec(\n              '12345678901234567890123456789012345678901234567890.1234567890123456789012345678901234567890123456789')))\n          .equals(\n              '12,345,678,901,234,567,890,123,456,789,012,345,678,901,234,567,890.123');\n    });\n\n    test('outputs the same result as origin', () {\n      // intl doesn't work with maximumFractionDigits > 15 on web and > 18 otherwise\n      const maxPreciseWebInt = 0x20000000000000;\n      final maxFractionalDigitsForIntl = log(maxPreciseWebInt) ~/ log(10);\n      final format = NumberFormat()\n        ..turnOffGrouping()\n        ..maximumFractionDigits = maxFractionalDigitsForIntl;\n      final formatter = DecimalFormatter(format);\n      final numbers = <String>[\n        '0',\n        '1',\n        '-1.123',\n        '123456789.0123',\n      ];\n      for (var number in numbers) {\n        expectThat(formatter.format(dec(number))).equals(number);\n      }\n\n      expectThat(formatter.format(dec(\n              '12345678901234567890123456789012345678901234567890.1234567890123456789012345678901234567890123456789')))\n          .equals(\n              '12345678901234567890123456789012345678901234567890.123456789012346');\n    });\n\n    test('with compactCurrency outputs the correct results', () {\n      final format = NumberFormat.compactCurrency(locale: 'en-US', symbol: '');\n      final formatter = DecimalFormatter(format);\n      expectThat(formatter.format(dec('1000000000'))).equals('1B');\n    });\n\n    test('with currencyFormatter', () {\n      final currencyFormatter = DecimalFormatter(NumberFormat.compact());\n      expectThat(currencyFormatter.format(dec('1000'))).equals('1K');\n      expectThat(currencyFormatter.format(dec('1000.1'))).equals('1K');\n      expectThat(currencyFormatter.format(dec('1234567890.1234')))\n          .equals('1.23B');\n    });\n  });\n  group('DecimalFormatter.parse', () {\n    test('handle invalid Decimal', () {\n      final plainFormatter = DecimalFormatter(NumberFormat());\n      expectThat(() => plainFormatter.parse('NaN')).throwsA<FormatException>();\n      expectThat(plainFormatter.tryParse('NaN')).isNull;\n      expectThat(() => plainFormatter.parse('a')).throwsA<FormatException>();\n      expectThat(plainFormatter.tryParse('a')).isNull;\n      expectThat(() => plainFormatter.parse('+Infinity'))\n          .throwsA<FormatException>();\n      expectThat(plainFormatter.tryParse('+Infinity')).isNull;\n    });\n    test('can parse plain decimal', () {\n      final plainFormatter = DecimalFormatter(NumberFormat());\n      expectThat(plainFormatter.parse('3.14')).equals(dec('3.14'));\n      expectThat(plainFormatter.parse('03.14')).equals(dec('3.14'));\n      expectThat(plainFormatter.parse('-3.14')).equals(-dec('3.14'));\n      expectThat(plainFormatter.tryParse('3.14')).equals(dec('3.14'));\n      expectThat(plainFormatter.tryParse('03.14')).equals(dec('3.14'));\n      expectThat(plainFormatter.tryParse('-3.14')).equals(-dec('3.14'));\n      expectThat(plainFormatter.tryParse('qsfd')).isNull;\n    });\n\n    test('can parse currency decimal', () {\n      final currencyFormatter =\n          DecimalFormatter(NumberFormat.simpleCurrency(name: 'USD'));\n      expectThat(currencyFormatter.parse(r'$3.14')).equals(dec('3.14'));\n      expectThat(currencyFormatter.parse(r'$03.14')).equals(dec('3.14'));\n      expectThat(currencyFormatter.parse(r'-$3.14')).equals(-dec('3.14'));\n      expectThat(currencyFormatter.tryParse(r'$3.14')).equals(dec('3.14'));\n      expectThat(currencyFormatter.tryParse(r'$03.14')).equals(dec('3.14'));\n      expectThat(currencyFormatter.tryParse(r'-$3.14')).equals(-dec('3.14'));\n      expectThat(currencyFormatter.tryParse('qsfd')).isNull;\n    });\n  });\n}\n"
  }
]