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 ...
随机推荐
- 通过url链接登录其他系统
目的:A系统通过链接跳转到其它系统(如B系统)并登录 技术方案 1.A系统用户登录B系统方案 1.A系统用户账号已经和B系统账号绑定,直接模拟登录 2.A系统用户账号未和B系统账号绑定 ...
- SqlParameter中的size
SqlParameter中size对于需要指定大小的数据库中的数据类型参数有影响[如nvarchar],如果对于这些类型没有指定size则会默认根据赋的值进行推导应该指定的size,而对于那些大小固定 ...
- mint锁屏设置
心血来潮,给笔记本装了linux,版本是当下最火的mint.唔,使用体验不错-下面记录的是修改mint锁屏相关设置的修改方式. In Linux Mint 13, the screen lock fe ...
- 轻量级应用开发之(07) UIPickerView使用
#import "ViewController.h" @interface ViewController ()<UIPickerViewDataSource,UIPicker ...
- 拉面馆中的移动互联网——无线KPI探讨
拉面馆中的移动互联网——无线KPI探讨 伴随着这几年超高速发展,移动互联网早已经度过了小米加步枪的散兵游击状态,随着各大公司持重金杀入,无线从几个人的Team,到快速发展为几十.上百人甚至上千人的大部 ...
- Mongo报如下类似错误时的修改方法Cannot natively represent the long 1396367483000 on this platform
今天通过php连接mongodb,并读取数据时,其中一个字段为: "createTime":NumberLong("1397524645000"),由于太长,一 ...
- js校验表单后提交表单的三种方法总结
第一种: 复制代码 代码如下: <script type="text/javascript"> function check(form) { if(fo ...
- MyBatis查询传一个参数时报错:There is no getter for property named 'sleevetype' in 'class java.lang.Integer
用MyBatis进行查询,传入参数只有一个时(非Map)如int,报错 There is no getter for property named 'sleevetype' in 'class jav ...
- Advice for applying Machine Learning
https://jmetzen.github.io/2015-01-29/ml_advice.html Advice for applying Machine Learning This post i ...
- xcrun: error: active developer path ("/Volumes/Xcode/Xcode-beta.app/Contents/Developer") does not exist, use `xcode-select --swi
xcrun: error: active developer path ("/Volumes/Xcode/Xcode-beta.app/Contents/Developer") d ...