A measurement and data type conversion library for Java, JavaScript and C#
Java
, JavaScript
and C#
./UnitOf-Examples/
provides in-depth runnable demo projects and examples for all languages of UnitOf.
Java
&C#
(NOTE: Written in Java but C# is the exact same only Pascal Cased methods)
/* For Java, same for C# but Pascal Cased methods. C# also uses Dictionary instead of HashMap for UnitOf.Anything parameter */
//One Liner
double a = new UnitOf.Mass().fromPounds(5).toKilograms(); //2.26796 returned as 5 pounds is 2.26796 kilograms
//Set Then Convert
UnitOf.Length feet = new UnitOf.Length().fromFeet(5.5); //Instantiate UnitOf.Length and set "feet" as 5.5
double b = feet.toInches(); //66 returned as 5.5 feet is 66 inches
double c = feet.toMeters(); //1.6764 returned as 5.5 feet is 1.6764 meters
//Convert Data Type and Fractions
double d = new UnitOf.DataType("12.5").toDouble(); //12.5 of type double returned. 0.0 would be returned if conversion failed
int e = new UnitOf.DataType("Not A Number").toInt(10); //10 of type int returned since conversion fails
String f = new UnitOf.DataType(0.5).toFraction(); //"1/2" of type String returned. Empty string would be returned if failed
//Create Your Own Custom Measurement
UnitOf.Anything x = new UnitOf.Anything("FEET", new HashMap<Object, Double>() {{ put("METERS", 0.3048); put("INCHES", 12.0); }});
double g = x.convertNow(36, "INCHES", "FEET"); //3 returned as 36 inches is 3 feet
double h = x.convertNow(3, "FEET", "METERS"); //0.9144 returned as 3 feet is 0.9144 meters
JavaScript
/* For JavasScript */
//One Liner
var a = UnitOf.Mass.fromPounds(5).toKilograms; //2.26796 returned as 5 pounds is 2.26796 kilograms
//Set Then Convert
var feet = UnitOf.Length.fromFeet(5.5); //Instantiate UnitOf.Length and set "feet" as 5.5
var b = feet.toInches; //66 returned as 5.5 feet is 66 inches
var c = feet.toMeters; //1.6764 returned as 5.5 feet is 1.6764 meters
//Convert Data Type and Fractions
var d = UnitOf.DataType("12.5").toFloat(); //12.5 of type Float returned. 0 would be returned if conversion failed
var e = UnitOf.DataType("Not A Number").toInt(10); //10 of type Int returned since conversion fails
var f = UnitOf.DataType(0.5).toFraction(); //"1/2" of type string returned. Empty string would be returned if failed
//Create your own custom measurement
var x = UnitOf.Anything("FEET", 1, true, {METERS:0.3048, INCHES:12}); //Custom measurement w/ 3 units
var g = x.convertNow(36, "INCHES", "FEET"); //3 returned as 36 inches is 3 feet
var h = x.convertNow("3", "FEET", "METERS"); //0.9144 returned as 3 feet is 0.9144 meters
Clone the UnitOf repo to your local machine using
https://github.com/digidemic/UnitOf
Only the single compiled UnitOf file of its language needs to be imported and referenced.
- Import
/UnitOf.jar
from the cloned repo into your project.- In your classes using UnitOf, add
import com.digidemic.unitof.UnitOf;
to your list of imports.
Properties
> Libraries
category > Compile
tab > Add JAR/Folder
> Navigate and select UnitOf.jar
from the cloned repo.Project
tab open > Switch folder structure to Project
> Expand the project and find the libs
directory (if not there create it in the same directory as src
and res
) > Add the UnitOf.jar
from the cloned repo to libs
directory > Right-click the newly added UnitOf.jar
node in the libs
directory > click Add As Library...
> Click OK
in the Create Library
dialog.npm install unitof
- Import
/UnitOf.min.js
from the cloned repo into your project- Add the following script tag (with the full path of
/UnitOf.min.js
) to the index html file:
<script src="/UnitOf.min.js"></script>
Install-Package UnitOf -Version 1.0.0
- Import
/UnitOf.dll
from the cloned repo into your project.- In your index class or any class needed, add
using UnitOf;
to your list of imports.
Solution Explorer
tab open > Expand the project directories navigating to References
> Right-click References
> Click Add Reference...
> Click Browser...
> Navigate and select UnitOf.dll
from the cloned repo > Make sure UnitOf.dll
is checked and click OK
.Java
, JavaScript
, or C#
).Java
, JavaScript
, and C#
instances of UnitOf.
Java
- UnitOf_v1.2.3.0JavaScript
- UnitOf_v1.2.3.0bC#
- UnitOf_v1.2.3.2aUnitOf website, logo, Palindrome Conversion Algorithm, and all source code & example projects for Java, JavaScript & C# created by Adam Steinberg of DIGIDEMIC, LLC