Skip to content

Instantly share code, notes, and snippets.

@CodeDrome
Created July 9, 2021 17:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save CodeDrome/b45ca9f443a60f3cc5bc127530fbbc02 to your computer and use it in GitHub Desktop.
Save CodeDrome/b45ca9f443a60f3cc5bc127530fbbc02 to your computer and use it in GitHub Desktop.
mathjsunits08.js
function power()
{
// demonstrate creating custom units
// this is metric horsepower, most commonly denoted by PS
// for pferd starke, German for horsepower
math.createUnit('ps', '735.49875 watt');
// The math.js hp is mechanical horsepower or approx 746 Watts
const power = math.unit(100, 'hp');
output(`power: ${power}`);
output(`power.to('kilowatt'): ${power.to('kilowatt')}`);
output(`power.to('ps'): ${power.to('ps')}`);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment