0

我有一个基于 Java+Spring MVC 的多语言 Web 应用程序。许多用户在他们的计算机上都有自己的语言环境。当他们尝试保存一些浮点值时 - 其中一些由于浮点数的差异而收到错误(其中一些有.,另一些有,)。

首先,我尝试使用org.apache.commons.validator.routines.FloatValidator来检查一个值是否为浮点数。然后我用来Float.parseFloat将验证值转换为浮点数。但问题是,在同一语言环境中失败时,价值FloatValidator.validate不会失败。17,11Float.parseFloat

所以我认为也许最好也使用一种FloatValidator.validate方法作为转换器?

4

1 回答 1

0

I recommend converting you number as in Convert input of BigDecimal locale dependent?". By using a NumberFormat you can specify the locale by which rules you would like to convert the number. You could also use the users locale to convert the number.

于 2013-07-12T08:27:18.757 回答