One day, you step onto a scale to determine your weight. It reads the number 150. What is this number? It is the force you are applying on to the scale. Europeans would be terrified to see this number, but Americans wouldn't even think twice. See, in the United States, scales read out units of pounds where in Europe, it would read out units of kilograms. What would a European scale say your weight is?
Now, here's an interesting predicament - pounds are units of force whereas kilograms are units of mass, which are completely different dimensions. In reality, a European scale is also measuring the force you apply, but in a different unit, called Newtons.
It just so happens that pounds are also units of mass, and on Earth, one pound of force equals one pound of mass. We'll get to this later.
So now that we know a European scale is actually measuring Newtons, what value would that be for
Follow these steps to create a new project workspace and install the dimensional dependency to run this example.
# Create and open project folder
mkdir Use_The_Force_demo
cd Use_The_Force_demo
# Initialize project and install dependencies
npm init -y
npm i dimensional@0.4.1
# Create and open source file
touch "Use The Force.mjs"
open "Use The Force.mjs"
Copy and paste this source code into Use The Force.mjs
.
import { Q, U } from 'dimensional';
// Weight is actually a force - not a mass!
// Therefore, units must be in pounds of force
const weight_lbs = Q(150, U({ pound_force: 1 }));
// We can easily obtain our weight in Newtons
// with a simple conversion using Quantity.as(unit)
const weight_N = weight_lbs.as(U({ Newton: 1 }));
// Print out the results of the conversion
console.log(weight_lbs.toString() + '=' + weight_N.toString());
// In case we want the raw value...
const weight_N_value = weight_N.value;
console.log('Raw value = ' + weight_N_value);
In Use_The_Force_demo/
, execute Use The Force.mjs
with NodeJS to generate an output.
node "Use The Force.mjs"
You should expect to see an output similar to the one below.
150 \left[\text{lb}_{f}\right]=667.2331370397568 \left[\text{N}\right]
Raw value = 667.2331370397568