如何格式化数字并输入 [英] How format number and put in input

查看:93
本文介绍了如何格式化数字并输入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个输入数字,我必须接受带有34,34个两位十进制数字的vlaue,所以我的代码是:

I have an input number and I must acept vlaue with 34,34 two decimal number so my code is:

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ page isELIgnored="false"%>
    <input type="number" min="0" name="price" pattern="0.00"
                        step=".01" required
                        value="<fmt:formatNumber type = "number" 
                        pattern="0.00" value = "${home.price}" />"

问题是inpput为空不会加载该值,因为如果我这样做

The problem is that the inpput is empty is not loaded the value, because if I do

<label><fmt:formatNumber type = "number" 
                    pattern="0.00" value = "${home.price}</label>

数字以正确的形式打印.有人可以帮助我吗?

the number is printed in the correct form. Anyone can help me?

推荐答案

使用fmt:formatNumber上的var属性存储结果并在输入中使用它,并确保您使用的语言环境提供的数字浏览器可以使用:

Use the var attribute on fmt:formatNumber to store the outcome and use it in your input, and make sure you are using a locale which provides numbers which the browser can work with:

<fmt:setLocale value="en"/>
<fmt:formatNumber type="number" 
                  pattern="0.00" value="${home.price}"
                  var="myNum"/>
<input type="number" min="0" name="price" pattern="0.00"
                    step=".01" required
                    value="${myNum}"/>

尤其是语言环境使它变得很丑陋,所以我真的建议您看看.

Especially the locale makes this quite ugly, so I really recommend to have a look at jsf.

另请参阅:

  • Localization of input type number (JSP)
  • JSTL formatNumber for JSP custom pattern independent from language
  • Formatting a double in JSF

这篇关于如何格式化数字并输入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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