zoukankan      html  css  js  c++  java
  • 在Salesforce中将 Decimal 数据转换成美元格式

    闲言少叙,直接上代码(Apex Class 中的方法):

        private string ConvertToMoneyFormat(decimal price){
            if (price == null || Math.abs(price) < 0.005) return '$0.00';
            String s = (price.setScale(2) + (price >= 0 ? 0.001 : -0.001)).format();
            return '$' + s.substring(0, s.length() - 1);
        }

    基本结果表现为:

    11 ----> $11.00

    1111 --->  $1,111.00

    1111.1 --->  $1,111.10

    1111.111 --->  $1,111.11

    若是在页面的控件中以美元显示,可以用如下方法:

    <apex:outputText value="{0, number, currency}">
        <apex:param value="{!EricSunCreditLimit}"/>
    </apex:outputText>

    或者用对数值进行一个更复杂的操作:

    <apex:outputText value="{0, number, ##}%" >
        <apex:param value="{!IF(EricSunCreditLimit>99 && EricSunCreditLimit<100 ,99,EricSunCreditLimit)}"/>
    </apex:outputText>

    再来一个:

    <apex:outputText value="{!'{0, number,###,###,##0.0}K'}">
        <apex:param value="{!ROUND(EricSunCreditLimit/1000,1)}"/>
    </apex:outputText>

    更多内容请看如下链接:

    http://salesforce.stackexchange.com/questions/318/what-is-a-concise-function-that-formats-a-string-decimal-into-a-currency-forma 

  • 相关阅读:
    iOS开发UI篇—xib的简单使用
    iOS开发UI篇—字典转模型
    iOS开发UI篇—九宫格坐标计算
    iOS开发UI篇—懒加载
    2020121301-01
    2020120501-01
    2020113001-梦断代码-3
    2020112801-01
    2020112401
    2020112201-1
  • 原文地址:https://www.cnblogs.com/mingmingruyuedlut/p/3745566.html
Copyright © 2011-2022 走看看