我可以格式化文本文件的数字值,但无法更新它 [英] I can format a number value of a textfiled but can not update it

查看:83
本文介绍了我可以格式化文本文件的数字值,但无法更新它的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试更新表单上的一些数字值.一旦显示的值没有格式,我可以轻松地将它们更改为任何数字,并将正确的数字发送到后端.但是,如果我输入一个大数字(例如6000000),它将在浏览器上更改为6.0E7,但是正确的数字将发送到后端.我添加了fmt库来格式化数字,但是当我提交表单时,它将0发送到后端.

I am trying to update few number values on a form. Once the values are shown without formation, I can easily change them to any number and correct number will be sent to the back-end; however, if I enter a big number such as 6000000, it will be changed to 6.0E7 on browser, but correct number will be sent to the back-end. I added fmt library to format the number but when I submit the form it sends 0 to the back-end.

<%@ taglib prefix="s" uri="/struts-tags"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>

<s:textfield id="price" name="price" value="%{price}" theme="simple"/>  //6.0E7


<input name="price" id="price" value='<fmt:formatNumber value='${price}'/>'/> //0

推荐答案

您不需要使用JSTL的fmt,Struts2内置了

You don't need to use JSTL's fmt, Struts2 has inbuilt Formatting Utilities:

然后代替

<s:textfield name="price" value="%{price}" />  
<!-- output: 6.0E7 -->

使用示例

<s:textfield name="price" value="%{getText('{0,number,#,##0.00}', {price})}" />
<!-- output: 6000000.00 -->

还要阅读有关类型转换的信息,并请记住6.0E7是此处了解更多).

Also read about Type Conversion, and keep in mind that 6.0E7 is Scientific Notation (read more here).

这篇关于我可以格式化文本文件的数字值,但无法更新它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆