我有一个变量V{Total}
,其中未应用模式###0.00
,我缺少什么?
<textField pattern="###0.00" isBlankWhenNull="false">
<reportElement uuid="ea9933c9-1863-474f-a6e2-65cfe3f07426" x="390" y="9" width="144" height="20" forecolor="#000000"/>
<box>
<pen lineColor="#999999"/>
<topPen lineColor="#999999"/>
<leftPen lineColor="#999999"/>
<bottomPen lineWidth="0.5" lineColor="#999999"/>
<rightPen lineColor="#999999"/>
</box>
<textElement>
<font fontName="Verdana" isBold="true" isUnderline="false"/>
</textElement>
<textFieldExpression><![CDATA[$V{Total}+".- €"]]</textFieldExpression>
</textField>
答案 0 :(得分:3)
您正在尝试格式化字符串:
$V{Total}+".- €"
将是一个字符串,即使该变量是十进制,添加.-€
也会将其转换为字符串,这意味着您的格式不起作用
你需要做的是自己格式化值并添加尾随字符,尝试这样的事情:
new DecimalFormat("###0.00").format($V{Total})+".- €"
完整解决方案:
<textField isBlankWhenNull="false">
<reportElement uuid="ea9933c9-1863-474f-a6e2-65cfe3f07426" x="390" y="9" width="144" height="20" forecolor="#000000"/>
<box>
<pen lineColor="#999999"/>
<topPen lineColor="#999999"/>
<leftPen lineColor="#999999"/>
<bottomPen lineWidth="0.5" lineColor="#999999"/>
<rightPen lineColor="#999999"/>
</box>
<textElement>
<font fontName="Verdana" isBold="true" isUnderline="false"/>
</textElement>
<textFieldExpression><![CDATA[new DecimalFormat("###0.00").format($V{Total})+".- €"]]></textFieldExpression>
</textField>