2017-08-31 17 views
0

我有我的课域地图类域

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

+0

你可以使用@BindUsing anno以确保您的表单与实体的绑定按照您的预期完成。 ref(Grails 3.1):http://docs.grails.org/3.1.x/guide/theWebLayer.html#_the_bindusing_annotation – bassmartin

回答

0

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

更改此

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

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

在您保存方法

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