搜尋套件、儲存庫與 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 項

原始碼儲存庫

使用此套件的專案