velocity的string转数字,非常有意思:

1、通过java的包装类进行转换

#set($intString = "20")
#set($Integer = 0)
$Integer.parseInt($intString)
#set($tring = "20")
#set($Double = 0.0)
$Double.parseDouble($string)

以上输出:

20

20.0

注意:velocity无法直接使用Integer(或Double),但是可以先定义一个整型变量(Double),使用这个整型变量的parseInt(“string”)转换。

先定义,再使用!

2、可以使用spring中的velocity的numberTool(numberToolAttribute属性):

    <bean id="velocityViewResolver"
class="com.banksteel.erp.web.common.utils.VelocityLayoutViewResolver">
<property name="layoutUrl" value="inc/layout.vm"/>
<property name="cache" value="false"/>
<property name="suffix" value=".vm"/>
<property name="exposeSpringMacroHelpers" value="true"/>
<property name="dateToolAttribute" value="dateTool"/>
<property name="numberToolAttribute" value="numberTool"/>
<property name="requestContextAttribute" value="req"/>
<property name="exposeRequestAttributes" value="true"/>
<property name="exposePathVariables" value="true"/>
<property name="toolboxConfigLocation" value="WEB-INF/tool-box.xml"/>
<property name="contentType" value="text/html;charset=UTF-8"/>
</bean>

$numberTool.format("0.00", "500");

3、NumberTool

org.apache.velocity.tools.generic.NumberTool

在toolbox.xml中配置如下所示:

<tool>
<key>number</key>
<scope>application</scope>
<class>org.apache.velocity.tools.generic.NumberTool</class>
<parameter name="format" value="#0.0"/>
</tool>

关于number,如下所示:

函数举例显示结果:

$number            org.apache.velocity.tools.generic.NumberTool@32c41c                            $number.currency("35")            ¥35.00                            $number.format            #0.0                            $number.locale            zh_CN                            $number.format("35")            35.0                            $number.integer("35.47")            35                            $number.number("35.47")            35.47                            $number.percent("0.3547")            35%                            $number.toNumber("35.47")            35.47         

以上!

注意:velocity的减法:“-”前后都要有空格!!!

velocity的string转数字,numberTool的更多相关文章

  1. String.Format数字格式化参考

    String.Format数字格式化输出 {0:N2} {0:D2} {0:C2} (转) 数字 {0:N2} 12.36 数字 {0:N0} 13 货币 {0:c2} $12.36 货币 {0:c4 ...

  2. String.Format数字格式化输出 {0:N2} {0:D2} {0:C2} (转)

    String.Format数字格式化输出 {:N2} {:D2} {:C2} (转) //格式为sring输出 // Label1.Text = string.Format("asdfads ...

  3. C#:String.Format数字格式化输出 {0:N2} {0:D2} {0:C2}等等

    int a = 12345678; //格式为sring输出//   Label1.Text = string.Format("asdfadsf{0}adsfasdf",a); / ...

  4. C#:String.Format数字格式化输出

    int a = 12345678; //格式为sring输出//   Label1.Text = string.Format("asdfadsf{0}adsfasdf",a);// ...

  5. .net String.Format数字格式化输出

    内容转载自:http://www.cnblogs.com/lqb/archive/2008/08/04/1259498.html 前面内容这个做的总结的很全,今后有新增的我继续往后补充.请留意我增加的 ...

  6. String.Format数字格式化输出 {0:N2} {0:D2} {0:C2

    //格式为sring输出 //   Label1.Text = string.Format("asdfadsf{0}adsfasdf",a); //   Label2.Text = ...

  7. 【转】C# String.Format数字格式化输出各种转换{0:N2} {0:D2} {0:C2}...

    ; //格式为sring输出 // Label1.Text = string.Format("asdfadsf{0}adsfasdf",a); // Label2.Text = & ...

  8. C# string 保留数字英文字母

    using System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressi ...

  9. EditText 数字范围 检查string 是不是数字

    public static boolean isNumeric00(String str){ try{ Integer.parseInt(str); return true; }catch(Numbe ...

随机推荐

  1. SQLHelper---赵晓虎(简洁,全面)

    public static class SQLHelper { //获取连接字符串,,首先添加对configuration的引用 private static string connStr = Con ...

  2. TYVJ1864 守卫者的挑战

    P1864 [Poetize I]守卫者的挑战 时间: 1000ms / 空间: 131072KiB / Java类名: Main 描述 打开了黑魔法师Vani的大门,队员们在迷宫般的路上漫无目的地搜 ...

  3. TCP/IP Four Layer Protocol Format Learning

    相关学习资料 tcp-ip详解卷1:协议.pdf 目录 . 引言 . 应用层 . 传输层 . 网络层 0. 引言 协议中的网络字节序问题 在学习协议格式之前,有一点必须明白,否则我们在观察抓包数据的时 ...

  4. php两种导出excel的方法

    所需要的:jquery库,phpexcel插件,页面导出excel效果测试文件explode.php,excel导出功能实现文件exp.php和explode_excel.php,文件相关内容在此文下 ...

  5. HDU 1054 Strategic Game(最小点覆盖+树形dp)

    题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=106048#problem/B 题意:给出一些点相连,找出最小的点数覆盖所有的 ...

  6. zoj3819Average Score

    Average Score Time Limit: 2 Seconds      Memory Limit: 65536 KB Bob is a freshman in Marjar Universi ...

  7. Why The Golden Age Of Machine Learning is Just Beginning

    Why The Golden Age Of Machine Learning is Just Beginning Even though the buzz around neural networks ...

  8. 笔记:PHP查询mysql数据后中文字符乱码

    新建表Clubs CREATE TABLE `Clubs` ( `id` ) NOT NULL AUTO_INCREMENT, `name` ) CHARACTER SET utf8 NOT NULL ...

  9. 安装hadoop2.4.0遇到的问题

    一.执行start-dfs.sh后,datenode没有启动 查看日志如下: 2014-06-18 20:34:59,622 FATAL org.apache.hadoop.hdfs.server.d ...

  10. BurpSuite之SQL Injection

    BurpSuite之SQL Injection[平台]:mutillidae[工具]BurpSuite 1.4.07 + FireFox1:安装配置mutillidae如果遇到问题,开下面的帖子.ht ...