我正在使用 xslt 2.0 和 Saxon 9.6,需要将价格金额和数量相乘,然后将结果四舍五入到小数点后两位。我不想要银行四舍五入,我想要四舍五入所以 .495 = 0.50 和 .494 = .49 。我尝试阅读有关此问题的几篇文章和帖子,但找不到解决方案。我看到几个地方由于浮点问题而使用 xslt 1.0 进行舍入是有问题的,并且很多人提到 xslt 2.0 和 xs:decimal 应该可以解决问题,但我似乎找不到“防水”解决方案。
我有一个 xml 文件(发票),其中包含 4 个不同的 InvoiceLines,其中包含价格和数量元素:
<Invoice>
<ID>12345</ID>
<IssueDate>2012-11-21</IssueDate>
<Supplier>
<Party>
<ID>977187761</ID>
</Party>
</Supplier>
<Customer>
<Party>
<ID schemeID="NO:ORGNR">810305282</ID>
</Party>
</Customer>
<Delivery>
<DeliveryDate>2012-11-21</DeliveryDate>
</Delivery>
<TaxTotal>
<TaxAmount currencyID="NOK">128.89</TaxAmount>
</TaxTotal>
<InvoiceLine>
<ID>1</ID>
<Quantity unitCode="EA">19</Quantity>
<LineAmount currencyID="NOK">130.26</LineAmount>
<Item>
<Name>TestItem</Name>
</Item>
<Price currencyID="NOK">8.569736842105263</Price>
</InvoiceLine>
<InvoiceLine>
<ID>2</ID>
<Quantity unitCode="NAR">1.00</Quantity>
<LineAmount currencyID="NOK">128.2</LineAmount>
<Item>
<Name>Vare A</Name>
</Item>
<Price currencyID="NOK">128.195</Price>
</InvoiceLine>
<InvoiceLine>
<ID>3</ID>
<Quantity unitCode="NAR">1.00</Quantity>
<LineAmount currencyID="NOK">128.7</LineAmount> …Run Code Online (Sandbox Code Playgroud)