|
Examples
JUGC examples
Featured Examples of JUGC usageExample unit definitions: <?xml version="1.0" encoding="UTF-8"?> <units> <unit> <id>gram</id> <alias>g</alias> </unit> <unit> <id>kilogram</id> <alias>kg</alias> <derive>gram</derive> <from>1000 /</from> </unit> </units> Doing an unit conversion in Java: Map<String, Unit> units = GeneratedUnits.createUnitsMap();
cf = new ConverterFactory(units, GeneratedUnits.getTranslations(units));
Converter pipe = cf.getConverter("gram", "kilogram");
pipe.convert(1000); // returns 1.0Doing an unit conversion in Python: um = create_units_map()
cf = ConverterFactory(um, get_translations(um))
c = cf.get_converter("g", "kg")
c.convert(1000) # returns 1.0
|
► Sign in to add a comment
Hi Juri - many thanks for jugc.
One of the things I like is the generation of implied conversions. Why not illustrate this in the example by adding another unit...
<unit> <id>tonne</id> <derive>kilogram</derive> <from>1000 /</from> </unit>Then the example of unit conversion could highlight that you get the implied gram to tonne conversion...
Converter c = cf.getConverter("gram", "tonne"); c.convert(1000000); // returns 1.0cheers Michael