1.0.2 • Published 5 years ago

@veinte_desarrollo/amount-formatter v1.0.2

Weekly downloads
4
License
ISC
Repository
-
Last release
5 years ago

Veinte - Amount formatter

Description

This library formats money amounts and prices, separating thousands with spaces and rounding or truncating to certain amount of decimals.

For example, rounding the price 10000.027 with to decimals would return 10 000.03.

Installation

npm install --save @veinte_desarrollo/amount-formatter

API

Format number

Formats a given number, separating thousands with spaces and rounding or truncating to certain amount of decimals, and returns it as a string

formatNumber(number, decimalPlaces, shouldRound)

  • number (string/float): the number which is going to be formated.
  • decimalPlaces(integer): indicates how many decimal places formatted number should have.
  • shouldRount(boolean): indicates if number should be rounded. If this parameter is not received, number is truncated.

Example:

console.log(formatNumber("1000000.139", 2)) // Returns "1 000 000.13"
console.log(formatNumber("1000000.139", 2, true)) // Returns "1 000 000.14"
console.log(formatNumber(1000000.139, 2, true)) // Returns "1 000 000.14"

Unformat number

Given a formatted number as string, it returns it as a float number.

unformatNumber(stringNumber)

  • stringNumber (string/float): the number which is going to be unformated.

Example:

console.log(unformatNumber("1 000 000.13")) // Returns 1000000.139
1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago