velocity的string转数字,numberTool
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的更多相关文章
- String.Format数字格式化参考
String.Format数字格式化输出 {0:N2} {0:D2} {0:C2} (转) 数字 {0:N2} 12.36 数字 {0:N0} 13 货币 {0:c2} $12.36 货币 {0:c4 ...
- String.Format数字格式化输出 {0:N2} {0:D2} {0:C2} (转)
String.Format数字格式化输出 {:N2} {:D2} {:C2} (转) //格式为sring输出 // Label1.Text = string.Format("asdfads ...
- C#:String.Format数字格式化输出 {0:N2} {0:D2} {0:C2}等等
int a = 12345678; //格式为sring输出// Label1.Text = string.Format("asdfadsf{0}adsfasdf",a); / ...
- C#:String.Format数字格式化输出
int a = 12345678; //格式为sring输出// Label1.Text = string.Format("asdfadsf{0}adsfasdf",a);// ...
- .net String.Format数字格式化输出
内容转载自:http://www.cnblogs.com/lqb/archive/2008/08/04/1259498.html 前面内容这个做的总结的很全,今后有新增的我继续往后补充.请留意我增加的 ...
- String.Format数字格式化输出 {0:N2} {0:D2} {0:C2
//格式为sring输出 // Label1.Text = string.Format("asdfadsf{0}adsfasdf",a); // Label2.Text = ...
- 【转】C# String.Format数字格式化输出各种转换{0:N2} {0:D2} {0:C2}...
; //格式为sring输出 // Label1.Text = string.Format("asdfadsf{0}adsfasdf",a); // Label2.Text = & ...
- C# string 保留数字英文字母
using System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressi ...
- EditText 数字范围 检查string 是不是数字
public static boolean isNumeric00(String str){ try{ Integer.parseInt(str); return true; }catch(Numbe ...
随机推荐
- G-nav-01
<body><header id="masthead" class="masthead" role="banner"> ...
- ovs-agent流程
1. 代码流程分析 neutron/plugins/openvswitch/agent/ovs_neutron_agent.py:main() plugin = OVSNeutronAgent(**a ...
- 在CentOS上装 ElasticSearch
参考官方文档:Install Elasticsearch with RPM ElasticSearch依赖Java,所以需要先安装Java: 到Oracle官网找到下载链接 http://www.or ...
- BZOJ-1001 狼抓兔子 (最小割-最大流)平面图转对偶图+SPFA
1001: [BeiJing2006]狼抓兔子 Time Limit: 15 Sec Memory Limit: 162 MB Submit: 14686 Solved: 3513 [Submit][ ...
- windows搭建openacs编译环境
1.下载ant工具用来编译openacs源码 apache-ant-1.8.2 下载地址http://ant.apache.org/ 这个文件不用编译,在目录bin/下有针对windows的ant 2 ...
- nginx配置ssl双向验证 nginx https ssl证书配置
1.安装nginx 参考<nginx安装>:http://www.ttlsa.com/nginx/nginx-install-on-linux/ 如果你想在单IP/服务器上配置多个http ...
- tmux下的滚屏
先Ctrl+b进入tmux的操作模式,然后用PageUp和PageDown,
- ci控制器写规范
不需要后缀名 文件名全部小写 所有控制器需要直接或者间接继承CI_Controller 以下划线开头的方法为私有方法,不能被请求 protected private的方法不能被浏览器请求 ci方法名不 ...
- pthread_cancel
#include <pthread.h> #include <stdio.h> #include<stdlib.h> #include <unistd.h&g ...
- SqlServer Link 链接服务器的使用
--创建linked exec sp_addlinkedserver 'a','','SQLNCLI','your ipaddress' --登陆linked exec sp_addlinkedsrv ...