Launch Week Day 1: Socket for Jira Is Now Available.Learn More
Socket
Book a DemoSign in
Socket

numberformat

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

numberformat

Based on jquery-numberformatter, without dependency on jquery, formats numbers based on a formatting string and a locale.

latest
npmnpm
Version
1.0.3
Version published
Maintainers
1
Created
Source

numberformat

Port from jquery.numberformatter, without parsing function and without dependency on jquery or jshashtable.

Originally written by Michael Abernethy (mike@abernethysoft.com), Andrew Parry (aparry0@gmail.com)

Licensed under the MIT (MIT-LICENSE.txt)

Dependencies

lodash.assign

Generic functions:

formatNumber(numberString, options) - Takes a plain number as a string (e.g. '1002.0123') and returns a string of the given format options.

To achieve the old way of combining parsing and formatting to keep say a input field always formatted to a given format after it has lost focus you'd simply use a combination of the functions.

e.g.

$("#salary").blur(function(){
     $(this).parseNumber({format:"#,###.00", locale:"us"});
     $(this).formatNumber({format:"#,###.00", locale:"us"});
});
The syntax for the formatting is:
0 = Digit
# = Digit, zero shows as absent
. = Decimal separator
- = Negative sign
, = Grouping Separator
% = Percent (multiplies the number by 100)

For example, a format of "#,###.00" and text of 4500.20 will display as "4.500,20" with a locale of "de", and "4,500.20" with a locale of "us"

As of now, the only acceptable locales are

  • Arab Emirates -> "ae"
  • Australia -> "au"
  • Austria -> "at"
  • Brazil -> "br"
  • Canada -> "ca"
  • China -> "cn"
  • Czech -> "cz"
  • Denmark -> "dk"
  • Egypt -> "eg"
  • Finland -> "fi"
  • France -> "fr"
  • Germany -> "de"
  • Greece -> "gr"
  • Great Britain -> "gb"
  • Hong Kong -> "hk"
  • India -> "in"
  • Israel -> "il"
  • Japan -> "jp"
  • Russia -> "ru"
  • South Korea -> "kr"
  • Spain -> "es"
  • Sweden -> "se"
  • Switzerland -> "ch"
  • Taiwan -> "tw"
  • Thailand -> "th"
  • United States -> "us"
  • Vietnam -> "vn"

Keywords

numbers

FAQs

Package last updated on 27 Jun 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts