Learn about our RFC process, Open RFC meetings & more.Join in the discussion! »

money_beans

1.0.3 • Public • Published

Money

Create JS money objects from strings, integers or floats

Get started

Money = require('money')
 
new Money()
# returns => Object {cents: 0} 
 
new Money('12.2')
# returns => Object {cents: 1220} 
 
new Money(195)
# returns => Object {cents: 19500} 
 

Render

Money = require('money')
price = new Money(10)
 
price.format()
# returns = '10.00' 
 
price.render()
# returns => "<span class='money positive'>$10.00</span>" 
 

Operations

Money = require('money')
 
## Multiply 
 
productPrice = new Money('49.95')
quantity = 3
subTotal = productPrice.multiply(quantity)
# returns => Object {cents: 14985} 
 
## Addition 
 
shipping = new Money('20')
total = subTotal.add(shipping)
# returns => Object {cents: 16985} 
 
## Subtraction 
 
discount = new Money('10')
finalTotal = total.subtract(discount)
# returns => Object {cents: 15985} 
 

Install

npm i money_beans

DownloadsWeekly Downloads

25

Version

1.0.3

License

MIT

Last publish

Collaborators

  • avatar
  • avatar