Giter Site home page Giter Site logo

trueanalyticssolutions / siunits Goto Github PK

View Code? Open in Web Editor NEW
1.0 2.0 0.0 40 KB

A library to help utilize and implement SI Units. Originally built to ease implementation of QIF standard.

License: MIT License

C# 100.00%
nist qif tams dotnet-standard si-units

siunits's Introduction

SIUnits

A library to help utilize and implement SI Units. This is not currently intended to be a direct reflection of the International System of Units.

Getting Started

A static set of units have been hardcoded into the library to help get you started.

List<SIUnits.Abstracts.AUnit> allUnits = SIUnits.UnitManager.GetUnits(); // Returns a list of all hardcoded SI Base, Derivitive, and Factored Units

You can iterate through each unit and understand more information about each one:

Type typDerived = typeof(SIUnits.DerivedUnit);
Type typFactored = typeof(SIUnits.FactoredUnit);

string strTableFormat = "{0,20}{1,20}{2,20}";

Console.ForegroundColor = ConsoleColor.White;
Console.WriteLine(strTableFormat, "Name", "Symbol", "Base Unit");
foreach (SIUnits.Abstracts.AUnit unit in allUnits) {
  Type typThisUnit = unit.GetType();
  if (typThisUnit.IsAssignableFrom(typFactored)) { // Is custom factored unit
    Console.ForegroundColor = ConsoleColor.Yellow;
  } else if (typThisUnit.IsAssignableFrom(typDerived)) { // Is SI Derived Unit
    Console.ForegroundColor = ConsoleColor.Blue;
  } else { // Is SI Base Unit
    Console.ForegroundColor = ConsoleColor.Green;
  }
  Console.WriteLine(strTableFormat, unit.Name, unit.Symbol, unit.Base.ToString());
}

You can also try to convert basic text into a converted measurement:

string strConvert = "33lb"; // How much the average Koala weighs
string strTargetUnit = "kg"; // Kilograms

decimal decKoalaWeight = (decimal)SIUnits.UnitManager.Convert(strConvert, strTargetUnit); // Cast because errors in conversion may return null

Console.WriteLine("A {0} Koala weighs about {1}{2}", strConvert, Math.Round(decKoalaWeight, 2).ToString(), strTargetUnit);

siunits's People

Contributors

jmurphy2973 avatar tbm0115 avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.