根据区域设置和货币格式化货币价值 [英] Format money value according to locale and currency

查看:144
本文介绍了根据区域设置和货币格式化货币价值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


可能重复:

我正在创建一个使用JasperReports的发票文档,需要进行本地化并支持多种货币。

I'm creating an invoice document using JasperReports that needs to be localized and support multiple currencies.

所以例如当报告时是法语,货币值应显示为 1,00€ 1,00 $ 以及在美国时英语应该是€0.02 $ 1.00

So for example when the report is in French, a currency value should be displayed as 1,00 € or 1,00 $ and when in US English it should be € 0.02 or $ 1.00.

至关重要的是,发票币种通常与当地货币不同,在某些情况下,同一份单据中可能会使用多种货币。

Crucially, the invoice currency is often different from the locale's currency, and in some cases there may be several currencies used in the same document.

我试过使用包含格式化工具:< textField pattern =¤#,## 0.00> ,但这并不会根据本地更改格式我和我找不到改变货币的方法(它只用报告的区域货币符号替换¤,因此在两个方面都是错误的。)

I've tried using the included formating tool:<textField pattern="¤ #,##0.00">, however this doesn't change the format according to the locale and I can't find a way of changing the currency (It only replaces the ¤ with the report's locale currency symbol, so wrong on both counts).

我看过这里:如何使用Java格式化区域设置的货币,但尚未找到在报告中使用此方法的方法。

I've taken a look here: How do I format a Currency for a Locale in Java but haven't figured out a way of using this in my reports.

谢谢!


好吧我终于明白了,但是因为mods锁定了这个问题,据说它是重复的 - 它不是......不管怎样,这里有一个答案:

Well I finally figured it out, but since the mods locked the question, supposedly it's a duplicate — WHICH IT IS NOT... anyway, here is one answer:

<variable name="CURRENCY" class="java.util.Currency">
     <variableExpression><![CDATA[Currency.getInstance($F{currencyCode})]]></variableExpression>
</variable>

<variable name="CURRENCY_FORMAT" class="java.text.NumberFormat">
    <variableExpression><![CDATA[
NumberFormat.getCurrencyInstance($P{REPORT_LOCALE});
((NumberFormat)value).setCurrency($V{CURRENCY})
]]></variableExpression>
</variable>

<textField>
     <reportElement x="179" y="58" width="89" height="15"/>
     <textFieldExpression><![CDATA[$V{CURRENCY_FORMAT}.format($F{revenueCents}/100)]]></textFieldExpression>
</textField>


推荐答案

ireport中有两个参数,REPORT_LOCALE和XML_LOCALE,可以帮助

There are two parameters in ireport, REPORT_LOCALE and XML_LOCALE, can help

这篇关于根据区域设置和货币格式化货币价值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆