【问题标题】:Variable Creation Issues变量创建问题
【发布时间】:2023-03-12 20:41:01
【问题描述】:

我正在使用 freemarker 引擎在 Netsuite 中创建一个快速模板(我第一次接触它),我正在努力寻找正确的语法来执行以下操作。

我有以下 2 个变量

item.rate & item.custcol_uom

我需要做以下事情

${formatAmount(item.rate/item.custcol_uom,"currency",".")}

任何帮助将不胜感激。

【问题讨论】:

    标签: freemarker netsuite


    【解决方案1】:

    Freemarker 为包括货币在内的数字提供多种格式指令

    ${(item.rate/item.custcol_uom)?string.currency}
    

    在此处查看文档:http://freemarker.org/docs/ref_builtins_number.html

    如果出于某种原因您更喜欢使用方法formatAmount(),您应该将其公开给freemarker引擎

    另一种解决方案是创建一个freemarker macro

    <@macro format_amount rate uom >
        <#-- stuff here -->
    </@macro>
    

    不如叫它

    <@s.format_amount rate=item.rate uom=item.custcol_uom />
    

    freemarker 中的宏:http://freemarker.org/docs/ref_directive_macro.html

    希望这会有所帮助。

    【讨论】:

    • 这很好用,非常感谢!我想我现在会坚持最好的方法,但感谢额外的细节。
    • 有没有简单的方法来控制应用的货币符号?
    • 如果您的格式与给定的语言环境(货币、十进制和千位格式、日期等)保持一致,请使用:
    • format_amount 当然应该是#function,而不是macro。但是,通常最好注册一个自定义数字格式,然后写${item.rate?string.@amount} 之类的东西;见freemarker.org/docs/pgui_config_custom_formats.html
    • @user1372212 货币符号由 Java 平台提供,基于 FreeMarker 的当前 locale 设置(fustaki 已经展示了一种可能的设置方式,但通常最好在外部设置它模板)。也可以在格式模式中明确指定它(参见freemarker.org/docs/…),例如'¤ ,##0;;currencyCode=USD'。您可能想在 FreeMarker 配置中将这些冗长的东西指定为别名格式,然后您可以编写 ${x?string.@usd} 等。
    猜你喜欢
    • 2020-10-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-09-29
    • 1970-01-01
    • 2018-03-20
    • 2017-10-21
    • 1970-01-01
    相关资源
    最近更新 更多