Closed
Conversation
Member
|
@gmponos I have some questions before coming to a solution.
And maybe you can try this one in the meanwhile. use Money\Number;
$money = $parser->parse((string)Number::fromNumber($amount), $currency); |
Contributor
Author
|
Hello, basically most of the questions can be answered through the test case that I have added. On the test case I just simulated the same thing as my App is doing but let's take it from the top and answer your questions just to be specific here:
I will give a try to the |
Contributor
Author
|
Any idea how this should be handled after all? |
Member
|
Closed in favour of #520. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Hello there....
I have an external API that executes some calculations and returns a result as a report. One of these results happened to be an amount that was a very very tiny one.
2.8865798640254e-15My code that consumes the API parses this value to a Money object automatically by doing:
I know that there is no actual currency that could represent a so tiny amount and it is practically zero (maybe in some bitcoins it have some value).
So the code above throws exception because the value is converted to a string in this form:
2.8865798640254e-15and this does not pass the expression inside the DecimalParser. For now in order to stop getting exception I had to do a quick solution to round the number to 7 decimals and then pass it inside the parser and it feels kinda hackish.As a better solution I could create something like a
ExponentialParserand pass it inside anAggregateParserbut before going into that I felt that I should ask if you believe that this should be handled by the DecimalParser and not by a different parser...If yes maybe I could implement the changes on this PR.
For my case above I have added a test case to check it.