项目作者: dperish

项目描述 :
Round and remove trailing zeros from JavaScript floating point types
高级语言: JavaScript
项目地址: git://github.com/dperish/prettyFloat.js.git
创建时间: 2014-08-27T07:11:04Z
项目社区:https://github.com/dperish/prettyFloat.js

开源协议:MIT License

下载


prettyFloat.js

Rounds and removes trailing zeros from JavaScript floating point types, and optionally localizes the output value to the current culture.

Arguments
-
prettyFloat(value, [precision = 0], [localize = false])

  • value - Float - Input value to prettify
  • precision - Int - Decimal to round at
  • localize - Boolean - Localize the output to the current culture’s format

-or-

(number).prettyFloat([precision = 0], [localize = false])

Usage:
-

  1. prettyFloat(1.111001, 3) // "1.111"
  1. prettyFloat(1.111001, 4) // "1.111"
  1. prettyFloat(1.1111001, 5) // "1.1111"
  1. prettyFloat(1234.5678, 2) // "1234.57"
  1. prettyFloat(1234.5678, 2, true) // "1,234.57" (en-US)
  1. (1234.5678).prettyFloat(2, true) // "1,234.57" (en-US)

Note:
-
All modern browsers now support the ECMAScript Internationalization API, which provides language sensitive string comparison, number formatting, and date and time formatting. For older browsers, you can use this polyfill: https://cdn.polyfill.io/v2/polyfill.min.js?features=Intl.~locale.en

License:
-
The MIT License (MIT) - http://opensource.org/licenses/MIT