-
Notifications
You must be signed in to change notification settings - Fork 143
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bug - fromCents
miscalculations in subsequent calculations
#425
Comments
That might be a bug, or at least I would probably flag that behavior is incorrect. I need to look into this further, but I would think at a high level both of your results should return the same value. |
Hey @scurker, thanks for your response. Agree, I'll try and take a look at this if I get a chance. |
Hi guys! I ran into the exact same issue as @jwarykowski and used the same workaround for "fixing" it. I believe the problem lies within the divide function that, as stated above, carries forward the Using the same values as the example above...
Maybe the returned instance of the divide function should "always" have the Or at least when is the result of dividing two currency objects? Thanks in advanced! |
Hi, here is a similar issue: const EURO = value => currency(value, { fromCents: true, symbol: '€', decimal: ',', separator: '.' });
function myFunction() {
let tottax = EURO(3000);
let vatrate = EURO(2200);
let totvat = EURO(tottax.divide(100).multiply(vatrate.value).intValue);
console.log(`tottax.value: ${tottax.value}`);
console.log(`totvat.value: ${totvat.value}`);
let totamo = totvat.add(tottax.value);
console.log(`vatrate: ${vatrate.value}<br>tottax: ${tottax.value}<br>totvat: ${totvat.value}<br>totamo: ${totamo.value}`);
} It's reporting |
Hi,
I noticed a weird problem when using a
fromCents
instance when performing further calculations down the line, please see the example below:You can see that the first example which uses the
fromCents
looks incorrect, if you don't pass this option I get the expected result. If possible can you confirm whether this is a bug or not? I've only had a quick look at this but any insight would be greatly appreciated. I wouldn't expect thefromCents
option to be carried forward in the returning instance.In order to get round this problem I can just wrap with another instance of currency and this works:
Note I use fromCents originally as the BE returns the value in centi cents
The text was updated successfully, but these errors were encountered: