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-02
/*header: Navigation public style*/header:before, header:after ,.navigation:before, .navigation:afte ...
- FastDFS在.Net平台上的使用
上一篇,了解了FastDFS是什么东东,一般稍微大一的网站都会做文件分离存储,FastDFS这轻型的分布式文件存储方式,非常有用. 此图片截取博友(张占岭)的勿喷 下面我们就了解一下,FastDFS在 ...
- Yii2 实现修改密码功能
YII2对密码加密生成的结果是不同的,即用相同的初始密码在不同时间得到的加密结果不同,所以我们不能用常用的方法去验证密码是否正确(将密码加密后与数据库中的密码相比较).YII2有自己的加密以及密码验证 ...
- 在Ubuntu下安装*.sh
在Ubuntu下安装*.sh和*.bin的方法 [日期:2009-12-07] 来源:Linux公社 作者:Linux编辑 [字体:大 中 小] 记下在Ubuntu下安装*.sh和*.bin的简 ...
- (Beta)Let's-版本发布说明
Let's App(Beta)现已隆重上市 GIT源码请戳此处 版本的新功能 我们在这一版本对于项目的规划目标主要集中在三个方面——预约用户观感,完善功能链条,改善用户体验 界面 首先,在β阶 ...
- Put-Me-Down项目Postmortem
设想和目标 PMD是一款帮助低头族控制使用手机时间的APP,设想按照需求规格说明书内容实现功能,能将数据备份到服务器. 计划 初始计划我们是想将程序方面分为安卓和后台,主要是程序方面的工作.我们对项目 ...
- Codeforce#331 (Div. 2) A. Wilbur and Swimming Pool(谨以此题来纪念我的愚蠢)
C time limit per test 1 second memory limit per test 256 megabytes input standard input output stand ...
- HD2157How many wasy??(十大矩阵问题之八 + 邻接矩阵的应用)
How many ways?? Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)T ...
- hdu 1013 Digital Roots
#include <stdio.h> int main(void) { int m,i;char n[10000]; while(scanf("%s",&n)= ...
- C++中 :: 的意思
表示作用域,和所属关系 ::是运算符中等级最高的,它分为三种:1)global scope(全局作用域符),用法(::name)2)class scope(类作用域符),用法(class::name) ...