我试图完全理解DecimalFormat的确切行为.我目前正在用这个类的科学记谱功能进行一些测试.而且我在调整科学记数法中有效位数的确切问题时遇到了问题.根据Java 7的Javadoc:
尾数中的有效位数是最小整数和最大小数位的总和,并且不受最大整数位数的影响.例如,用"## 0.## E0"格式化的12345是"12.3E3".要显示所有数字,请将有效数字计数设置为零.有效位数不会影响解析.
因此,我正在测试它:
DecimalFormat formatone = new DecimalFormat("##0.##E0");
System.out.println(formatone.format(toF));
Run Code Online (Sandbox Code Playgroud)
我获得以下输出:
12,345E3
Run Code Online (Sandbox Code Playgroud)
根据我刚刚展示的Javadoc的摘录,我想我应该获得
12.3E3
Run Code Online (Sandbox Code Playgroud)
难道我做错了什么 ?我理解错了吗?
在此先感谢您的所有澄清:-)
我正在尝试使用Java 7中提供的JAXB实现来处理一些XML文件.我正在使用这些版本:
501 ~ % xjc -version
xjc 2.2.4
502 ~ %java -version
java version "1.7.0_01"
Java(TM) SE Runtime Environment (build 1.7.0_01-b08)
Java HotSpot(TM) Server VM (build 21.1-b02, mixed mode)
Run Code Online (Sandbox Code Playgroud)
XML模式中有问题的解码如下:
<xsd:complexType name="CategorizeType">
<xsd:complexContent>
<xsd:extension base="se:FunctionType">
<xsd:sequence>
<xsd:element ref="se:LookupValue"/>
<xsd:element ref="se:Value"/>
<xsd:sequence minOccurs="0" maxOccurs="unbounded">
<xsd:element ref="se:Threshold"/>
<xsd:element ref="se:Value"/>
</xsd:sequence>
<xsd:element ref="se:Extension" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="thresholdBelongsTo"
type="se:ThresholdBelongsToType" use="optional"/>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>
Run Code Online (Sandbox Code Playgroud)
正如您所看到的,se中有两个显式出现:Type中的值.但是,它不会停止使用xjc进行编译.如果我查看为此类型生成的Java类,我可以看到在逻辑上可以检索元素
<xsd:sequence minOccurs="0" maxOccurs="unbounded">
<xsd:element ref="se:Threshold"/>
<xsd:element ref="se:Value"/>
</xsd:sequence>
Run Code Online (Sandbox Code Playgroud)
使用以下方法:
public List<Object> getThresholdAndValue() {
if (thresholdAndValue == null) { …Run Code Online (Sandbox Code Playgroud)