Frage

Is there any straight forward way to convert bar to psi(Pounds per square inch)?, like converting mm to inch

   //mm to inches
    Unit<Length> mm = SI.MILLIMETER;
    Unit<Length> in = NonSI.INCH;
    UnitConverter toInch = mm.getConverterTo(in);

    double d1 = toInch.convert(Measure.valueOf(10.0,mm).doubleValue(mm));
    Measure<Double, ? extends Quantity> convert1 = Measure.valueOf(d1, in);
    System.out.println(convert1);

I can convert it by multiplying (1 bar = 14.5037738 psi to the value) manually, But is there any other way to achieve below lines of code?

 //bar to psi
    Unit<Pressure> bar = NonSI.BAR;
    Unit<? extends Quantity> psi = NonSI.POUND.divide(NonSI.INCH.pow(2));
    UnitConverter toPsi = bar.getConverterTo(psi);// not compitable error

    double d2 = toPsi.convert(Measure.valueOf(10.0,bar).doubleValue(bar));
    Measure<Double, ? extends Quantity> convert2 = Measure.valueOf(d2, psi);
            System.out.println(convert2);
War es hilfreich?

Lösung

You should use POUND_FORCE instead of POUND.

POUND_FORCE.divide( INCH.pow(2) ).getConverterTo( BAR )

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top