Skip to content
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

Measure.of(<value>, bytes) yields value in bits #168

Closed
tymokvo opened this issue Jul 30, 2021 · 3 comments
Closed

Measure.of(<value>, bytes) yields value in bits #168

tymokvo opened this issue Jul 30, 2021 · 3 comments

Comments

@tymokvo
Copy link

tymokvo commented Jul 30, 2021

Hello!

From the readme, I expected:

console.log(Measure.of(72, bytes).toString());

to print 72 B

but, the result is 576 b as the underlying value created by Measure.of is in bits.

This is a bit confusing as other higher order units behave as I would expect them to, e.g.:

console.log(Measure.of(72, kilograms).toString());

yields 72 kg rather than 72000 g.

Using v1.1.0 with Typescript v4.3.5.

@Darkhogg
Copy link

Darkhogg commented Nov 18, 2021

your kilogram example works because kilograms is the base unit of mass, but if you were to use pounds instead

console.log(Measure.of(72, pounds).toString());
// prints: 32.658650640000005 kg

you should use .in instead to print in a particular unit:

console.log(Measure.of(72, bytes).in(bytes));

@tymokvo
Copy link
Author

tymokvo commented Nov 18, 2021

Makes sense! But still confusing. Maybe a reference to the SI base units in the documentation would help? For those of us (like me 😬 ) who haven't taken physics for a while?

NIST has a good reference here, though it is US-centric. The ISO standard is paywalled, unfortunately.

@jscheiny
Copy link
Owner

jscheiny commented May 17, 2024

I know I'm a little late on this (😬), but there is a reference to this in the documentation here: https://jscheiny.github.io/safe-units/builtin.html#base-units

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants