is there any library in java for unit conversion?
I want to use unit conversions like kg to grams, lit to ml, etc.. is there any java library and my-sql tables, available for this ?
I was asked to use JScience so now I have to populate all the units in JScience into a JCombo box or a list box.. Tel me hod开发者_StackOverflow中文版 do i do that please ?
You can use JScience...
Here's an example to convert kilogram to gram:-
double gram = Measure.valueOf(5, SI.KILOGRAM).doubleValue(SI.GRAM);
System.out.println(gram);
Here are all the available units:-
for (Unit<?> unit : SI.units()) {
System.out.println(unit);
}
The print outs:
m/s?
F
lm
A
C
N
H
J
lx
K
m/s
Wb
m?
Gy
T
W
kg
V
Ω
S
kat
Pa
sr
m
m?
mol
bit
°C
Hz
s
Bq
Sv
rad
cd
By the way, I'm using the JRE 1.4 compatible binary from JScience, and I also need JSR 275 (I pulled that from Maven):
<dependency>
<groupId>javax.measure</groupId>
<artifactId>jsr-275</artifactId>
<version>1.0.0</version>
</dependency>
Here're my import statements, if anyone cares:-
import javax.measure.units.SI;
import javax.measure.units.Unit;
import org.jscience.physics.measures.Measure;
精彩评论