Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

number-formatierer

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

number-formatierer

Format a number with commas

  • 1.0.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

number-formatierer

GitHub repo size Build Status npm (tag) GitHub

Install

npm install --save number-formatierer 
or 
yarn add number-formatierer

Usage

var numberFormat = require('number-formatierer')
//import numberFormat from 'number-formatierer' ES6

numberFormat("-12.0000")   // "-12"
numberFormat(120000)  // "120,000"
numberFormat(-120000,  2) // "-120,000.00"
numberFormat(131277.092213, 2, 3)  // "131,277.09"
numberFormat(131277.092213, 2, 3, "#") // "131#277.09"
numberFormat(131277.092213, 2, 3, "#","|") // "131#277|09"

API

numberFormat(inputNumber, precision, digit, separator, decimalChar)

Parameters:

  • inputNumber(required) : {(Number|String)} Number to format .
  • optionalPrecision: {Number} precision for the decimal .
  • optionalDigit: {Number} digits of the separator. default 3
  • separator : {String} Value used to separate numbers. default ','
  • decimalChar : {String} Value used to separate the decimal value. default '.'

Returns:

  • {String} formatted number, if {inputNumber} is not a number or string, that will be that self

bindWith(precision, digit, separator, decimalChar)

The numberFormat function accepts these same parameters as the second and third params. This prevents using currying to bind them and reuse that bound function.

The bindWith function accepts the options and returns a function bound with them.

var numberFormat = require('number-formatierer')
//import numberFormat from 'number-formatierer' ES6

const _bindWith = numberFormat.bindWith(2, 4, ",", ".")
_bindWith(131277.092213);  // 13,1277.09

toFixed(num, precision)

same as number.toFixed and More accurate than number.toFixed

Parameters:

  • num(required) : {(Number)} Number .
  • precision: {Number} precision for the decimal . default 3 .
var numberFormat = require('number-formatierer')
//import numberFormat from 'number-formatierer' ES6

numberFormat.toFixed(0.015, 2); // 0.02
numberFormat.toFixed(0.025, 2);  // 0.03
numberFormat.toFixed(0.035, 2);  // 0.04
numberFormat.toFixed(0.045, 2);  // 0.05

(0.015).toFixed(2); //0.01
(0.025).toFixed(2); //0.03
(0.035).toFixed(2); //0.04
(0.045).toFixed(2); //0.04

Acknowledgement

Comma number

Keywords

FAQs

Package last updated on 21 Apr 2023

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc