Search code examples
javamathcad

How to write units in Java like Radian, Newton, Pascal, mm, kg?


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 = ?

Solution

  • 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.