Giter Site home page Giter Site logo

valueconversion's Introduction

mvdmio.ValueConversion

mvdmio.ValueConversion can be used to create values for a specific unit, and convert those values to another unit of the same quantity at run-time. Based on examples of UnitsNet.

Base package

This package contains the entry point for working with values of a given unit or quantity. Make sure to include the child packages with the specific types you need for your project.

The child packages are:

  • mvdmio.ValueConversion.Currency
  • mvdmio.ValueConversion.UnitsOfMeasurement

Currency

The Currency package contains Quantity definitions for Currency.

The following currency units are defined:

  • UnitedStatesDollar
  • Euro
  • MexicanPeso
  • CanadianDollar

Units of Measurement

The UnitsOfMeasurement package contains Quantity definitions for a wide range of SI quantities.

The following UnitsOfMeasurement quantities are defined:

  • Angle (e.g. Degree or Radian)
  • Area (e.g. SquareMeter, Hectare, or Acre)
  • Distance (e.g. Meter, Kilometer, or Inch)
  • Duration (e.g. Second, Day, or Decade)
  • ElectricConductance (e.g. Siemens or Millisiemens)
  • Energy (e.g. Joule, Calorie, or KilowattHour)
  • Mass (e.g. Kilogram, Tonne, or Ounce)
  • pH
  • Power (e.g. Watt, MetricHorsePower, or Kilowatt)
  • Pressure (e.g. Pascal, Bar, or PoundForcePerSquareInch)
  • Ratio (e.g. Percent or PartsPerMillion)
  • Substance (e.g. Mole or Micromole)
  • Temperature (e.g. DegreeCelsius, DegreeFahrenheit, or Kelvin)
  • Volume (e.g. CubicMeter, Liter, or CubicInch)

As well as a couple of pre-defined (named) combined quantities:

  • ElectricConductivity (ElectricConductance / Distance)
  • Irradiance (Power / Area)
  • Velocity (Distance / Duration)

Usage Examples

For all examples, see the Example project in this repository.

Temperature: Celsius to Fahrenheit.

var temperatureInCelsius = new QuantityValue(10, Temperature.DegreeCelsius);         // 10 °C
var temperatureInFahrenheit = temperatureInCelsius.As(Temperature.DegreeFahrenheit); // 50 °F

var formattedCelsius = temperatureInCelsius.GetFormattedValue(decimalPoints: 2);
var formattedFahrenheit = temperatureInFahrenheit.GetFormattedValue(decimalPoints: 2);
Console.WriteLine($@"{formattedCelsius} = {formattedFahrenheit}"); 

Temperature: Fahrenheit to Kelvin

var temperatureInFahrenheit = new QuantityValue(93, Temperature.DegreeCelsius); // 93 °F
var temperatureInKelvin = temperatureInFahrenheit.As(Temperature.Kelvin);       // 366.15 K

var formattedFahrenheit = temperatureInFahrenheit.GetFormattedValue(decimalPoints: 2);
var formattedKelvin = temperatureInKelvin.GetFormattedValue(decimalPoints: 2);
Console.WriteLine($@"{formattedFahrenheit} = {formattedKelvin}"); 

Distance: Meters to Yards

var distanceInMeters = new QuantityValue(10, Distance.Meter); // 10 meter
var distanceInYards = distanceInMeters.As(Distance.Yard);     // 10.94 yd
 
var formattedMeters = distanceInMeters.GetFormattedValue(decimalPoints: 2);
var formattedYards = distanceInYards.GetFormattedValue(decimalPoints: 2);
Console.WriteLine($@"{formattedMeters} = {formattedYards}"); 

Distance: Kilometers to Miles

var distanceInMeters = new QuantityValue(100, Distance.Kilometer); // 100 km
var distanceInMiles = distanceInMeters.As(Distance.Mile);          // 62.14 mi

var formattedMeters = distanceInMeters.GetFormattedValue(decimalPoints: 2);
var formattedMiles = distanceInMiles.GetFormattedValue(decimalPoints: 2);
Console.WriteLine($@"{formattedMeters} = {formattedMiles}");

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.