Skip to content

Commit

Permalink
424: Scaling / multiplication is unable to apply factors to temperatures
Browse files Browse the repository at this point in the history
  • Loading branch information
keilw committed Sep 29, 2024
1 parent e545e25 commit 4e72aee
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package tech.uom.demo.impl.seshat;

import javax.measure.IncommensurableException;
import javax.measure.UnconvertibleException;
import javax.measure.UnitConverter;

import tech.uom.seshat.UnitServices;

public class TemperatureConverterDemo {

public static void main(String[] args) {
var format = UnitServices.current().getFormatService().getUnitFormat();

var source = format.parse("°C/10");
var dest = format.parse("°C");
UnitConverter converter = null;
try {
converter = source.getConverterToAny(dest);
} catch (UnconvertibleException | IncommensurableException e) {
e.printStackTrace();
}
if (converter != null) {
var converted = converter.convert(10);
System.out.println(converted);
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package tech.uom.demo.java17;

import javax.measure.IncommensurableException;
import javax.measure.UnconvertibleException;
import javax.measure.UnitConverter;
import javax.measure.spi.ServiceProvider;

public class TemperatureConverterDemo {

public static void main(String[] args) {
var format = ServiceProvider.current().getFormatService().getUnitFormat();

var source = format.parse("°C/10");
var dest = format.parse("°C");
UnitConverter converter = null;
try {
converter = source.getConverterToAny(dest);
} catch (UnconvertibleException | IncommensurableException e) {
e.printStackTrace();
}
if (converter != null) {
var converted = converter.convert(10);
System.out.println(converted);
}
}

}

0 comments on commit 4e72aee

Please sign in to comment.