accounting vs currency.js vs format-number vs numeral
数字格式化和货币处理库
accountingcurrency.jsformat-numbernumeral类似的npm包:

数字格式化和货币处理库

这些库主要用于在JavaScript中处理数字和货币格式化。它们提供了便捷的API来格式化、解析和操作数字,特别是在涉及货币和财务数据时。通过使用这些库,开发者可以轻松地确保数字显示符合当地的文化和货币标准,从而提升用户体验和数据的可读性。

npm下载趋势

3 年

GitHub Stars 排名

统计详情

npm包名称
下载量
Stars
大小
Issues
发布时间
License
accounting04,980-14512 年前-
currency.js03,382-615 年前MIT
format-number050-69 年前BSD-3-Clause
numeral09,704-3459 年前MIT

功能对比: accounting vs currency.js vs format-number vs numeral

功能特性

  • accounting:

    accounting.js提供了简单的货币格式化、数字格式化和基本的数学运算功能。它支持自定义货币符号和小数位数,非常适合快速实现基本的财务计算。

  • currency.js:

    currency.js专注于货币计算,支持多种货币和精确的数学运算。它允许链式调用,提供了丰富的API来处理货币转换和格式化。

  • format-number:

    format-number专注于数字的格式化,支持多种格式选项,包括千位分隔符、百分比等。它非常灵活,适合需要多种数字格式的场景。

  • numeral:

    numeral.js是一个功能强大的数字格式化库,支持多种语言和自定义格式。它提供了丰富的格式化选项,适合需要复杂数字展示的应用。

使用场景

  • accounting:

    适合需要快速实现货币显示和简单计算的应用,例如电商网站的价格显示。

  • currency.js:

    适合需要处理多种货币和复杂计算的金融应用,例如在线支付系统。

  • format-number:

    适合需要多种数字格式的应用,例如数据可视化和报表生成。

  • numeral:

    适合需要全面数字格式化的应用,例如仪表盘和统计分析工具。

学习曲线

  • accounting:

    accounting.js的API简单易懂,适合初学者快速上手。

  • currency.js:

    currency.js的学习曲线稍陡,需要理解其链式调用和货币计算的概念。

  • format-number:

    format-number的API直观,易于学习,适合各种开发者。

  • numeral:

    numeral.js功能强大,但由于其丰富的选项和格式,可能需要一定时间来熟悉。

本地化支持

  • accounting:

    accounting.js支持基本的货币符号自定义,但对本地化的支持有限。

  • currency.js:

    currency.js支持多种货币和本地化选项,适合国际化应用。

  • format-number:

    format-number支持多种数字格式,适合不同地区的数字展示。

  • numeral:

    numeral.js具有强大的本地化支持,可以根据不同的语言和地区格式化数字。

扩展性

  • accounting:

    accounting.js相对简单,扩展性有限,适合小型项目。

  • currency.js:

    currency.js提供了丰富的API,支持自定义扩展,适合大型项目。

  • format-number:

    format-number的设计灵活,允许用户自定义格式,适合多样化需求。

  • numeral:

    numeral.js支持插件和自定义格式,具有很高的扩展性,适合复杂应用。

如何选择: accounting vs currency.js vs format-number vs numeral

  • accounting:

    如果你需要一个轻量级的库来处理基本的货币格式化和数字计算,且希望有简单的API,选择accounting是个不错的选择。

  • currency.js:

    如果你的应用需要处理复杂的货币计算,特别是涉及到多种货币和精确度要求,currency.js提供了强大的功能和灵活性。

  • format-number:

    如果你需要一个专注于数字格式化的库,且希望支持多种格式和选项,format-number是一个理想的选择。

  • numeral:

    如果你需要一个功能全面的库来处理数字格式化,并且希望支持多种语言和自定义格式,numeral是一个强大的选择。

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