映射类域

时间:2017-08-31 11:28:30

标签: grails

我有我的班级域名

class domain Factura {
    String name
    BigDecimal value
}

在我的HTML中:

<g:form>
   <input type="text" name="name" />
   <input type="number" step="any" name="value" />
   <inpu type="submit" value="save" />
</g:form>

在我的控制器中

def save(Factura factura) {
 //Suppose in the value I have put :   152.36
 println "valor: " + factura.value   => return 15236.0

 //Suppose in the value I have put :   152,36
 println "valor: " + factura.value   => return 15236.0

}

如何以小数形式返回?我需要152.36

1 个答案:

答案 0 :(得分:0)

您可以使用文本输入并将其强制转换为BigDecimal

更改此

<input type="number" step="any" name="value" />

<input type="text" name="value" />

在您的保存方法

try{
    params.value.toBigDecimal()
catch(e){
   // error
}