Grails - 输入字段显示点 ('.) 而不是 (',') 表示十进制数字



在edit.gsp中,我有十进制数的输入字段,十进制数显示为"3.123",如果我保存它:我得到了错误,因为小数点是错误的!它需要一个","。我所在的地方是瑞典。所以我必须手动将所有十进制数字的句点替换为逗号。

我找了整整一个星期都找不到解决办法。Grails不应该是一致的,并且在保存时显示逗号吗?它应该同时适用于BigDecimal和for double。

我有圣杯3.2.4

以下是一个来自编辑表单的"g:field"示例:

Bredd: <g:field type="number decimal" name="width" min="20" max="300" required="Y" value="${request1?.width}" style="width: 4em"/>

那么,我能做什么呢?

manually replacing dots听起来很可怕,可能是错误的方法。

移动了周围的答案段

因此,自从我今天遇到类似的问题以来,答案的更新可能是相反的。由于其他原因验证失败时,通过多个3333发送该字段中的数字在验证失败后变为3,333。如果旧的验证问题得到修复,那么由于数字中的逗号,它现在将失败。原因原来是:

<g:textField value="${fieldValue(bean: instance, field: 'someField')}"

返回时,将号码更改为3333,将其更改为

value="${instance.someField}"

以上是@larand面临的实际问题

我会将输入字段width存储为一个短

所以:

Class MyClass {
//if you are storing a number like 123 (non decimal)
Short width
//if you are storing 12.12 which becomes 1212 when stored
Integer width
BigDecimal getDecimalWidth() {
return new BigDecimal(this.width).movePointRight(2).setScale(2)
}
void setWidth(BigDecimal decimal) {
this.width=new BigDecimal(decimal).movePointLeft(2).setScale(2)
}
//unsure but think this should work
Integer getWidthInteger() {
return this.width as int
}
void setWidth(Integer integer) {
this.width=(byte)integer
}
}

这将为您提供使用${instance.decimalWidth}或整数获取短值的方法:${instance.widthInteger}

当您的字段实际上是数字时:

<g:formatNumber number="${myCurrencyAmount}" type="currency" currencyCode="EUR" />

对我来说,这似乎比你认为的削减数字更直接、更干净——

在第一个验证问题之后,输入的数字是3333。所以这可能是您的问题?不确定,因为你说的是点

最新更新