Comments (4)
Hi @strzibny,
I think this is a great idea.
For input values, I think we can expand the capabilities of the parse
function, now supported strings and floats.
Workaround for current functionality:
iex(7)> Decimal.cast(2.5) |> Decimal.to_float() |> Money.parse!()
%Money{amount: 250, currency: :USD}
I think to_decimal
is a good name for the conversion function.
If you want to contribute, pull requests are welcome.
from money.
Do you think that something like the following is fine for the reverse?
money_str = Money.to_string(money, separator: "", delimiter: ".", symbol: false)
{:ok, decimal} = Decimal.parse(money_str)
from money.
It's a working option, but it's better to work with numbers.
iex(17)> price = Money.new(25, :USD)
%Money{amount: 25, currency: :USD}
iex(18)> price_in_float = price.amount / Money.Currency.sub_units_count!(price)
0.25
iex(19)> Decimal.from_float(price_in_float)
#Decimal<0.25>
This will give the same result, but it will avoid unnecessary conversions and the math will not depend on formatting settings.
from money.
@Nitrino yes, that would work better :)
from money.
Related Issues (20)
- Return atoms from compare instead of -1/0/1 HOT 2
- Add a decimal precision money type
- [Question] How do you define a form input in eex for a Money.Ecto.Composite.Type ? HOT 3
- Possible Bug with live and validations? HOT 2
- Compare should return `:gt | :eq | :lt` HOT 2
- Warning when compiling with Elixir 1.11.0-rc.0 HOT 4
- Wrong Format when you show symbol in a Negative amount HOT 6
- How to round? HOT 2
- [request] money object with a scale option HOT 1
- Dynamically adding currency HOT 1
- Support phoenix_html 3.x HOT 1
- Truncate/Human readable option? HOT 1
- Question: Currency conversion HOT 1
- Parsing with Float HOT 3
- Incorrect currency Symbols
- Parsing string HOT 1
- Question - Change decimal precision HOT 2
- Incorrect currency symbol HOT 4
- Protocol Undefined Error when rendering the amount on a Form HOT 2
- Breaking change between 1.11 and 1.12 HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from money.