safe-units icon indicating copy to clipboard operation
safe-units copied to clipboard

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

Open tymokvo opened this issue 4 years ago • 2 comments

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.

tymokvo avatar Jul 30 '21 21:07 tymokvo

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));

Darkhogg avatar Nov 18 '21 10:11 Darkhogg

Makes sense! But still confusing. Maybe a reference to the SI base units in the documentation would help? For those of us (like me :grimacing: ) 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.

tymokvo avatar Nov 18 '21 17:11 tymokvo