Reputation: 179
I am developing a Java application, its about converting Mathcad worksheet to Java application. Can anyone know/suggest how to write units(newton, pascal, mm, kg)in java code?
Example:1?
double var1 = 10*newton/mm;//looking for a way to write the code in this format.
double var2 = 5*mmpower2;
double var = var1/var2;
double var = ?
Example: 2?
double var1 = 90degress-tan(60)*Radian;
double var1 = ?
Upvotes: 1
Views: 459
Reputation: 308998
Neither of your examples are sensible Java.
You want to implement the Martin Fowler Analysis Patterns idea of Quantity with units.
There are libraries that exist, like JScience, but I don't know if they're in widespread use.
Upvotes: 0
Reputation: 10575
You could use the Javax.units package, especially the Java Unit Class.
This is a well-studied problem and for any non-trivial program you should always use an existing units library.
Upvotes: 3