如何将POW写入Java单位(JScience)



我正在使用 JSCIENCE API 编写单元,但是我无法使用POW方法。如何为单位写功率?

Unit<Length> centimeter = SI.CENTIMETER;
//Unit<Length> cm3 = centimeter.pow(3);eclipse suggests to add cast
Unit<Length> cm3 = (Unit<Length>) centimeter.pow(3);
System.out.println(cm3); // prints cm? instead of cm^3

我认为这是一个UTF-8 3-Superscript?

另请参阅此处:http://www.fileformat.info/info/unicode/char/char/char/char/index.htm

您可以通过分析cm3.toString()

的字节来检查它
byte[] bs = cm3.toString().getBytes("UTF-8");
for ( byte b : bs )
{
    System.out.println( b );
}

下一个字符串的我的输出(使用3个上标):

byte[] bs = "cm³".getBytes( "UTF-8" ); // byte[] bs = "cmu00B3".getBytes( "UTF-8" );
for ( byte b : bs )
{
    System.out.println( b );
}
99
109
-62
-77

如果第一个字节数组的字节与第二个字节相同,则输出是正确的,但是您的控制台无法显示字符³

最新更新