Giter Site home page Giter Site logo

js-money's People

Contributors

alexander-hq avatar caccialdo avatar davidkalosi avatar dnfrolov avatar levacic avatar niepi avatar romanenko avatar stylet avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

js-money's Issues

Documentation issue

The documentation states that, for example, to add money, one can do the following:

fiveEur.add(250, Money.EUR); // 7.50 EUR

However, inspecting the code and testing shows that this is not the case; instead, the correct way seems to be:

fiveEur.add(new Money(250, Money.EUR))

Is that correct? If so, I guess the docs should be fixed to reflect that - I can send a PR if you don't have the time, just wanted to check first.

Outdated currency code for Zambian Kwacha

The currency definition for Zambian Kwacha uses currency code, that went out of use in 2012.
Previous code: ZMK
Current code: ZMW

I noticed there is a pull request, that already fixes this issue, among others. Could you please consider merging the PR?

Thank you for this great package!

Why not always add decimals?

Is there a reason you have decided to not always append decimals to the amount? It might seem confusing when you make money out of 1000 you get 1000, but when you make money out of 1000.00 you get 100000.
Should it not be consistent?

npmjs.com?

I'm unfamiliar with publishing npm packages - how can we get 0.5.0 into npmjs.com?

Bitcoin currency?

Is there a reason why BTC hasn't been added to currencies.js? If there is no problem, I'd do a PR with this:

"BTC": { "symbol": "BTC", "name": "Bitcoin", "symbol_native": "B͈̎", "decimal_digits": 8, "rounding": 0, "code": "XBT", "name_plural": "Bitcoins" },

What about toDecimal?

I'm implementing this for the first time so perhaps this is something obvious but if I want to eventually output the money as a decimal is this not something which should live within the money object code?

Seems odd that you would safely be able to do calculations whilst it is represented as cents but then you risk causing an issue by having to do the toDecimal implementation yourself.

Thanks in advance for any advice

Is this repository still maintained?

Hi, I would like to know if this repository is being maintained. I saw there haven't been commits for a long time.
If not, do you know any alternative?
I'm interested on the converter interface mentioned in #29.
Also, I think the source code is a little bit outdated, using prototypes makes it harder to read, maybe it could be rewritten in TypeScript or at least plain JavaScript with classes

Possibly wrong result after multiplication

Multiplying these two numbers together seems to yield the wrong result:

Money.fromDecimal(2090.50, Money.USD).multiply(Money.fromDecimal(8.61, Money.USD)).toDecimal() // = 17999.2

Should be 17999.21.

Internally I think this is what happens:

209050 * 8.61 // = 1799920.499999999....
Math.round(1799920.4999999998) // = 1799920

fromDecimal throws 'Amount must be an integer'

While using your library, I ran across some unexpected behavior.

require('js-money').fromDecimal(78.13, 'USD');
{ amount: 7813, currency: 'USD' }

require('js-money').fromDecimal(78.43, 'USD');
TypeError: Amount must be an integer

A little digging into the code revealed that this is just a variant of the floating point rounding errors that I had hoped to avoid in the first place.

78.13*100
7813

78.43*100
7843.000000000001

This then trips the check in the Money constructor which throws the above TypeError. Is there any feasible workaround for this?

Add more helper methods

Hi! Looks like this library lacks the following methods:

  • greaterThan
  • greaterThanOrEqual
  • lessThan
  • lessThanOrEqual
  • getAmount
  • getCurrency

It will significantly improve readability of code that was written with the usage of this library.

Documentation fails to mention that unit is sometimes cents

I can see the need to internally store the amount in a different format than a floating point Number, but I think it would make total sense to hide that implementation detail from the rest outside world. Otherwise, you easily end up with situations where suddenly, $100 has grown into $10000 for no apparent reason, aside from the joy it might bring to your accounting department. :)

Look at these examples:

> (new Money(1, Money.USD)).compare( new Money(1, Money.USD) )
0 // true
> Money.fromDecimal(1.0, Money.USD).compare( new Money(1, Money.USD) )
1 // uh oh

AMD Support?

I've been researching how to do this, but I'm a bit at a loss. Any idea on how to implement AMD support? I am currently using browserify to load this into Ember, but an AMD option would be nice.

Money.fromDecimal not always reliable without rounder

Currently the Money.fromDecimal relies on Math.pow(10, currency.decimal_digits) and will not work correctly with some numbers unless a rounder like Math.ceil is passed in when being used.

Example:
var money = Money.fromDecimal('2067.22', 'USD');

Result:
206721.99999999997

Generates error for isInt check on line 63 & 64:

if (!isInt(amount))
        throw new TypeError('Amount must be an integer');

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.