How can I pass a string from String to decimal?

1

I need to pass a String string that is in an object of type JTextField to a BigDecimal variable or any other data type that can store values of this type "785,292.90" and then store them in the DB (decimal (65, 0) )

    
asked by HectoRperez 16.03.2018 в 00:27
source

1 answer

0

You can not use operators like '/' or '*' with objects, for example BigDecimal. If you want to do operations you have to use the methods offered by the class. For example:

 BigDecimal p = new BigDecimal("123.1231255");
 BigDecimal d = new BigDecimal(12.32);
 //el metodo divide solo admite otro BigDecimal en este caso.
 double a = p.divide(d).doubleValue();

If you want to see a complete list of methods that can be used in the Java documentation appear.

    
answered by 20.03.2018 в 16:23