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
Unit toSI() uses 'mm' instead of 'm' for small 'ft' values #1336
Comments
I think how |
Jos, I'm not certain. I don't think the intent was to auto-select the best prefix. This could be a bug. |
Looking at the unit tests of mathjs/test/type/unit/Unit.test.js Lines 1240 to 1264 in 638ed7e
|
Anyone interested in helping to fix this bug? |
I should be able to get to it within a week or two. |
Okay it was easier than I thought. On a similar note, I really dislike the side-effects in |
I could not agree more |
@BjoernSimon this issue should be fixed now in @ericman314 would it work if we would create a method |
I think so. Perhaps the right way to approach this is to make Units immutable, and refactor all the methods as necessary. I imagine the API could change significantly so it might be a breaking change. Edit: After looking at the existing functions, must units are cloned rather than mutated, so I think we could keep the API essentially the same. |
Moving towards immutability is a good thing in my book 👍 |
PR #1344 removes the side-effects. |
In the refactoring I'm working on (#71) I smashed quite some times into issues around mathjs functions not being immutable but for example listening for config changes, which makes it impossible to really isolate them and get tree-shaking working, see my comment here: #71 (comment). The refactoring really pushes us towards pure functions, which is great! |
I think we can close this issue, it was solved by Eric already. |
I am using Math.js Units to parse a string value and always convert it to the SI system to normalize the values. This works very well except for small 'ft' length and 'ft^2' area values. I did not try it for other units as I am assuming this is a generic issue.
Issue 1:
Unit.parse('0.111 ft^2').toSI()
converts into'10312.23744 mm^2'
instead of'0.01031223744 m^2'
Issue 2:
getting the 'unit' from JSON immediately after constructing it e.g. via
Unit.parse(value).toSI().toJSON().unit)
returns'm^2'
(correct SI unit) instead of'mm^2'
(the unit it was incorrectly converted to, see issue 1).Please see example code and output below for details.
Results in
The text was updated successfully, but these errors were encountered: