Results 1 to 2 of 2
  1. #1
    Ch4os is offline Member
    Join Date
    Nov 2008
    Posts
    7
    Rep Power
    0

    Default [SOLVED] float in java and in mysql

    I noticed some differences in the float type while using netbeans and mysql.

    while netbeans uses 7.5 mysql uses 7,5..
    I don't know why they are different and how.

    The following is what I am trying to achieve.

    Grades
    7,6 counts 3 times
    7,5 counts 3 times
    7,3 counts 3 times

    7,9 counts 1 times
    8,6 counts 1 times
    6,5 counts 1 times

    gradescounted:
    90,2

    totalgrades:
    12

    Average:
    7,516666667

    I want to set the average to 1 decimal like this
    7,5

    Java Code:
    // Creates a DecimalFormat for setting the float to 1 decimal
    DecimalFormat FloatFormat = new DecimalFormat("0.0");
    // Calculates the average
    Average = Float.valueOf(FloatFormat.format(gradescounted/totalgrades));
    then I get a error:
    java.lang.NumberFormatException: For input string: "7,5"

    I don't know if that is related with the fact that netbeans and mysql uses different seperator or how to solve this problem.

    Any solution is welcome, thanks in advance.

  2. #2
    Ch4os is offline Member
    Join Date
    Nov 2008
    Posts
    7
    Rep Power
    0

    Default

    I solved it,

    the FloatFormat creates a string (7,5)
    then I use replace to replace the , with a .
    then I convert te string into a float with Float.valueof();

Similar Threads

  1. mysql connector to java
    By sweet angle in forum JDBC
    Replies: 4
    Last Post: 10-20-2008, 06:33 AM
  2. How to combine mysql and java?
    By sandeeprao.techno in forum Advanced Java
    Replies: 1
    Last Post: 05-21-2008, 04:41 AM
  3. MySQL Database and Java
    By shaggymac in forum Advanced Java
    Replies: 1
    Last Post: 05-01-2008, 09:01 PM
  4. java to mysql
    By thamizhisai in forum New To Java
    Replies: 12
    Last Post: 04-28-2008, 07:48 AM
  5. java to mysql
    By thamizhisai in forum Advanced Java
    Replies: 1
    Last Post: 04-26-2008, 08:21 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •