Conversion not working
michaeladam3010 opened this issue · 2 comments
Hi,
first: thank you for your great work!
Using your library I discovered that:
Measure.of(1, radians.per(seconds)).in(degrees.per(seconds)).toString() returns "1 rad / s"
I expected it to return ~"57 deg / s"
Did I do something wrong?
Best regards
Michael
Hey Michael, thanks for reaching out!
This is a reasonable question, the problem here is that the expression degrees.per(seconds)
has no symbol associated with it since we can't infer symbols from expressions like this. As such, we can't properly format in terms of that unit so we call back to the underlying unit which is rad/s in this case.
To fix this you can make a degrees per second measure with a symbol and use it to format as follows:
const degreesPerSecond = degrees.per(seconds).withSymbol("deg / s");
const result = Measure.of(1, radians.per(seconds)).in(degreesPerSecond);
Side note: The in
method returns a string, no need to call toString()
afterwards.
Let me know if you have anymore issues. Also take a look at the docs here: https://jscheiny.github.io/safe-units/measures.html#symbols (see this section and the following one on formatting). Curious to know if these would have been sufficient to answer your question and if not, how could they be improved/fixed to help understand-ability.
Hi Jonah,
thank you for your fast reply.
The documentation itself is excellent! Though the main issue was that I wasn't able to find it when I was looking out for it (shame on me). It would be nice if you could also add the link to the documentation (https://jscheiny.github.io/safe-units/) to the Readme.md ;-)
Cheers,
Michael