Dealing with Struts2 float conversion type

Posted by Daniel Calderon Mori on Stack Overflow See other posts from Stack Overflow or by Daniel Calderon Mori
Published on 2012-06-30T03:14:02Z Indexed on 2012/06/30 3:15 UTC
Read the original article Hit count: 170

Filed under:

I have a question regarding float type conversion in Struts2.

I have a form that contains a serie of normal input elements.

A serie of textfields with an add button by the side of each one is included in the window. Clicking on one of this buttons has the effect of adding an input type "hidden" inside the form with the value of its correspondent textfield. That value will often be a float number that, this is very important, uses the point format (example: 1.34).

The inputs created look like this:

<input class="hidden_material" type="hidden" name="form[0].cantidad_formulacion" value='1.34'">
<input class="hidden_material" type="hidden" name="form[1].cantidad_formulacion" value='1.54'">

Anyway, the whole proccess is made correctly until the data is used by the server after the form submission. The numbers are present as if the point wouldn't have been placed in the number (using the example above, as 134).

If a comma is used (as in 1,34), there wouldn't be a problem. But that will not be the case with the users of the system. How could I solve this problem?

© Stack Overflow or respective owner

Related posts about struts2