搜索插件、代码仓与 APP 分类

插件详情v6.3.0

fixed

具有数学运算、格式化和解析功能的固定精度小数。

AndroidiOSWebmacOSWindowsLinux
近 30 天下载
15.7万
喜欢数
12
Pub 分数
160

安装插件

flutter pub add fixed

插件介绍

基于插件公开信息、社区数据与项目使用情况整理的选型参考。

该固定包提供对固定精度小数的支持,可实现精确的数学运算、格式化和解析。通过以固定的小数位数表示数字,确保一致的十进制精度,避免浮点数不准确的问题。适用于金融计算以及需要精确十进制算术的场景,提供可靠的加法、减法、乘法和除法运算,并支持正确的舍入处理。该包支持多种平台,包括 Android、iOS、Web、macOS、Windows 和 Linux。

适合场景

  • 财务计算
  • 精确的十进制算术
  • 货币处理
  • 固定精度的数据序列化
  • 需要精确小数的科学计算

主要特点

  • 固定小数位数比例
  • 精确的算术运算
  • 内置格式化和解析
  • 对大数的支持
  • 跨平台兼容性

适合对象

  • 需要精确十进制数学的开发人员
  • 财务或会计应用
  • 需要一致的十进制表示的应用程序
  • 避免浮点数错误的团队

使用建议

  • 需要仔细选择缩放系数
  • 仅限固定精度
  • 可能对密集计算带来性能开销
  • 不适合任意精度需求

原始 README

以下为关联源码仓库的 README 原文快照,最新内容请访问源码仓库。

The Fixed package allows you to store and perform math on decimal numbers with a fixed scale (fixed no. of decimal places).

All amounts are stored as BigInts to allow precision math to be performed.

The features of Fixed are:

  • Fixed uses a selectable fixed scale (no. of decimal places)
  • Fixed provides a builtin formatter and parser Fixed.format(pattern)
  • Full set of mathematical opertors.
  • Fixed includes a convenience method Fixed.formatIntl(locale) which formats the number with the provided locale or the default locale if not provided.

Sponsors

Fixed is sponsored by OnePub, the Dart private package repository.

OnePub

You can create a Fixed instance from a number sources

var t1 = Fixed.fromNum(1); /// == 1.00
var t2 = Fixed.fromNum(1, decimalDigits: 3); /// == 1.000

var add = t1 + 10;
var multiply = t1 * t2;

var t3 = Fixed.parse("1.23356"); // == 1.23356, decimalDigits: 5

if (t1 == t2) // true
{
    print(t1.format('0.##')); // '1.00'
    print(t3.format('0.###')); // '1.123'
}

Full documentation can be found here.

所属分类

依赖

依赖清单 3 项

源码仓库

使用此插件的项目