accounting vs d3-format vs numbro vs numeral
数字格式化库
accountingd3-formatnumbronumeral类似的npm包:

数字格式化库

数字格式化库用于在Web开发中处理和显示数字数据。这些库提供了多种功能,包括货币格式化、百分比格式化、数字分隔符等,帮助开发者以用户友好的方式展示数字信息。选择合适的库可以提高代码的可读性和维护性,同时增强用户体验。

npm下载趋势

3 年

GitHub Stars 排名

统计详情

npm包名称
下载量
Stars
大小
Issues
发布时间
License
accounting04,980-14512 年前-
d3-format064442.3 kB167 个月前ISC
numbro01,1421.27 MB2692 年前MIT
numeral09,704-3459 年前MIT

功能对比: accounting vs d3-format vs numbro vs numeral

功能丰富性

  • accounting:

    accounting.js专注于货币格式化和简单的数学运算,功能相对简单,适合快速实现基本需求。

  • d3-format:

    d3-format提供了强大的格式化功能,支持复杂的数字格式和自定义格式,适合数据可视化场景。

  • numbro:

    numbro提供了多种格式化选项和本地化支持,适合需要处理多种语言和地区的应用。

  • numeral:

    numeral.js功能全面,支持多种格式化选项,包括货币、百分比和自定义格式,适合各种应用场景。

本地化支持

  • accounting:

    accounting.js对本地化支持有限,主要集中在英语和一些基本的货币格式。

  • d3-format:

    d3-format对本地化支持较弱,主要用于数据可视化,不专注于多语言环境。

  • numbro:

    numbro提供了强大的本地化支持,支持多种语言和地区格式,适合国际化项目。

  • numeral:

    numeral.js也提供了一定的本地化支持,但不如numbro全面,适合一般的应用需求。

学习曲线

  • accounting:

    accounting.js的学习曲线较平缓,API简单易懂,适合初学者快速上手。

  • d3-format:

    d3-format的学习曲线相对较陡,尤其是对于不熟悉D3.js的开发者,可能需要时间来理解其复杂的格式化选项。

  • numbro:

    numbro的API设计合理,学习曲线适中,适合有一定JavaScript基础的开发者。

  • numeral:

    numeral.js的学习曲线较平缓,API清晰易用,适合各种水平的开发者。

性能

  • accounting:

    accounting.js性能优越,适合处理简单的数字格式化和计算,适合小型项目。

  • d3-format:

    d3-format在处理复杂格式化时性能表现良好,但在高频率调用时可能会影响性能。

  • numbro:

    numbro的性能良好,适合需要频繁格式化的场景,尤其是在国际化应用中。

  • numeral:

    numeral.js在性能上表现稳定,适合各种规模的项目,能够处理大量数据的格式化。

扩展性

  • accounting:

    accounting.js的扩展性有限,主要用于基本的货币和数字格式化,不支持复杂的自定义需求。

  • d3-format:

    d3-format具有较高的扩展性,能够与D3.js的其他功能结合使用,适合复杂的数据可视化需求。

  • numbro:

    numbro的扩展性较好,支持自定义格式和本地化,适合需要灵活处理数字的项目。

  • numeral:

    numeral.js的扩展性强,支持多种格式化选项和自定义功能,适合各种应用场景。

如何选择: accounting vs d3-format vs numbro vs numeral

  • accounting:

    选择accounting.js如果你需要一个轻量级的库来处理货币格式化和简单的数学计算。它提供了简单易用的API,适合快速开发和小型项目。

  • d3-format:

    选择d3-format如果你正在使用D3.js进行数据可视化。它提供了强大的格式化功能,能够处理复杂的数字格式,适合需要高度自定义格式的应用。

  • numbro:

    选择numbro如果你需要一个支持多种语言和地区的数字格式化库。它提供了灵活的API和本地化支持,适合需要国际化的项目。

  • numeral:

    选择numeral.js如果你需要一个功能全面且易于使用的数字格式化库。它支持多种格式化选项,包括货币、百分比和自定义格式,适合各种规模的项目。

accounting的README

accounting.js is a tiny JavaScript library for number, money and currency parsing/formatting. It's lightweight, fully localisable, has no dependencies, and works great client-side or server-side. Use standalone or as a nodeJS/npm and AMD/requireJS module.

Visit the plugin homepage for demos and documentation: http://openexchangerates.github.io/accounting.js/

Please checkout or download the latest stable tag before using in production. Bug reports and pull requests are welcome.

Maintained by Open Exchange Rates and originally by @josscrowcroft and other contributors.


Works great with:

  • money.js - a tiny (1kb) standalone JavaScript currency conversion library, for web & nodeJS
  • Open Exchange Rates - the free currency conversion data API

Changelog

v0.4.1 - Alias accounting.formatNumber() as accounting.format()

v0.4 - Transferred repository to Open Exchange Rates for ongoing maintenance

v0.3.2 - Fixed package.json dependencies (should be empty object)

v0.3.0

  • Rewrote library structure similar to underscore.js for use as a nodeJS/npm and AMD module. Use npm install accounting and then var accounting = require("accounting"); in your nodeJS scripts.
  • Also works with requireJS or any AMD module loader.
  • unformat now only attempts to parse the number if it's not already a valid number.
  • acounting.unformat now also aliased as acounting.parse
  • Fixed an IE bug in the defaults method

v0.2.2 - Fixed same issue as #Num: #24 in formatNumber; switch to Google Closure Compiler for minified version.

v0.2.1 - Fixed issue #Num: #24 (locally-defined settings object was being modified by formatMoney)

v0.2

  • Rewrote formatting system for formatMoney and formatColumn for better control of string output
  • Now supports separate formats for negative and zero values (optionally) via accounting.settings.currency.format
  • Internal improvements and helper methods

v0.1.4

  • formatMoney recursively formats arrays
  • Added Jasmine test suite (thanks to millermedeiros) and QUnit functionality/speed tests

v0.1.3

  • Added configurable settings object for default formatting parameters.
  • Added format parameter to control symbol and value position (default "%s%v", or [symbol][value])
  • Methods consistently accept object as 2nd parameter, matching/overriding the library defaults

v0.1.2

  • formatColumn works recursively on nested arrays (e.g. accounting.formatColumn( [[1,12,123,1234], [1234,123,12,1]] ), returns matching array with inner columns lined up)
  • Fix rounding in formatNumber

v0.1.1

  • Added toFixed method (accounting.toFixed(value, precision)), which treats floats more like decimals for more accurate currency rounding
  • Minified version preserves semicolons
  • Fixed NaN errors when no value in unformat

v0.1 - First version