-
Notifications
You must be signed in to change notification settings - Fork 188
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
Passing decimals as amount #58
Comments
Hey @sarneeh and thanks for the suggestion. You're not the first one to ask and it could indeed be interesting to add this, maybe as a static method or as a separate factory (to keep the bundle size untouched for those who don't need it). I guess it could auto-detect the precision based on the number of digits after the decimal point, which would be even simpler. Something like: DineroFactory.fromFloat({ amount: 499.99, currency: 'EUR' }) Would that help? |
@sarahdayan Indeed! This idea is a lot better as it keeps the Dinero API consistent! That would definitely help 😃 I could also implement this, but unfortunately not in the nearest 1-2 months (gotta fight deadlines). If you don't mind this late date you could keep this up here for me 😃 |
@sarneeh In this case we can share the load and get this out sooner: I can implement it and you could review (should demand less time than implementing). Would this be doable for you? |
@sarahdayan I'll find time for a review for sure! Thank you! |
Very excited about this feature. I'd love to be able to pass in strings and have them parsed into the object. Ex: "$150" -> {amount: 15000} |
@jadamduff This would be the job of another factory, such as |
@sarahdayan okay thank you |
I'd be interested in taking this on @sarahdayan if you haven't started already. |
Can we simply use |
@captDaylight On it already, but thanks for offering your help! Would love it if you want to review. |
Hi @sarahdayan The factory with fromFloat/fromString methods is already available? I do not find anything about it Thanks |
@blacktrue Hey, I'm still working on it, but got delayed 🙂 If you subscribe to notifications for this issue you'll get pinged once the PR that fixes it is merged and the version that embarks it is deployed. |
@sarahdayan hey, are you in need of a helping hand? If you're swamped with work I might be able to give it a try. From a first thought, it seems that something like
in |
Hey @ishegg, thanks for offering your help! I'm indeed swamped with work, had to put this on the back burner. Feel free to PR 🙂 |
Hey! I just published a RFC for Dinero.js v2 🚀 It tackles this specific problem. I would love to have your feedback on it: dinerojs/rfcs#1 cc @ishegg @sarneeh @jadamduff @captDaylight @fish4j |
I am looking exactly for this. When will be released? Thanks. |
wouldn't it be better to integrate some other library like decimal.js or bignumber.js or big.js? or how exactly can you use dinero if you're using one of those libraries? If I understand correctly dinero doesn't use any of them and is using integers to do decimal calculations? |
@bugproof You probably don't want to use multiple money formatting libraries, as it's only adds unnecessary complexity. The case of this issue is to be able to more easily integrate |
@Huespal I'm currently not able to tackle this because of work, so I can't give you an ETA. Feel free to PR if you need it ASAP, I can take time to review. @bugproof There are several things to consider. First, it's much better to use non-floats (as |
it's problematic when you have API that returns decimal values like 666.66 how can you pass it as amount to dinero? multiply by 100?
|
Any updates on this? |
Hi , I just discovered dinero.js and I think this issue is very necessary because most of the time money is used with text-masking and the value returned from masking doesn't come in cents. For example currently I use react text-mask addon and when I give 5000 cents Dinero object as input value I get back $50.00 as string. My workaround is to remove the currency, then parse the float, then multiply by 100 (while controlling the minimum sub unit for the currency). I think these are necessary..I will try doing these in my fork
this is 'nice to have' EditI couldn't make the library work with the change in static.js similar to what @ishegg stated but in my React code I made the parsing work with masking as below.
|
Why not allow a
Users of |
Hey! I just released Dinero.js v2 in alpha. It doesn't provide decimal support out of the box, but I've written a guide on how to do it userland. The new design makes it straightforward to extend the library. I would still recommend being cautious with floats, and make sure what you're passing is really the amount you intended. |
Looks like I'm coming at perfect timing ✌🏻 |
Is your feature request related to a problem? Please describe.
So if you would like to integrate with services like Braintree (or any other service that uses decimals instead of minor currency values) you will have to manually convert those decimals/strings to integers just to make it compatible with Dinero.
Describe the solution you'd like
It would be great if I could just pass a string like
499.99
into Dinero and it would convert it into49999
. This could be achieved for example with afromFormat
function which would take a string mask argument and a value:fromFormat('0.00', '499.99')
.Describe alternatives you've considered
Manual conversion.
The text was updated successfully, but these errors were encountered: