(double)(x/y)
(double)x/y 只能将x变为double

解决方案 »

  1.   

    int x= 7,y= 3;
    double a =(double) x/y;这个我试过了,没问题阿。
      

  2.   

    (double)(x/y)  会丢掉小数点后的部分
      

  3.   

    integer to String :    int i = 42;
      String str = Integer.toString(i);
      or
      String str = "" + idouble to String :  String str = Double.toString(i);long to String :  String str = Long.toString(l);float to String :  String str = Float.toString(f);
    String to integer :  str = "25";
      int i = Integer.valueOf(str).intValue();
      or
      int i = Integer.parseInt(str);String to double :  double d = Double.valueOf(str).doubleValue();String to long :  long l = Long.valueOf(str).longValue();
      or
      long l = Long.parseLong(str);String to float :  float f = Float.valueOf(str).floatValue();decimal to binary :  int i = 42;
      String binstr = Integer.toBinaryString(i);decimal to hexadecimal :  int i = 42;
      String hexstr = Integer.toString(i, 16);
      or
      String hexstr = Integer.toHexString(i);hexadecimal (String) to integer :  int i = Integer.valueOf("B8DA3", 16).intValue();
      or
      int i = Integer.parseInt("B8DA3", 16); ASCII code to String  int i = 64;
      String aChar = new Character((char)i).toString();
    integer to ASCII code (byte)  char c = 'A';
      int i = (int) c; // i will have the value 65 decimal
    To extract Ascii codes from a String    String test = "ABCD";
        for ( int i = 0; i < test.length(); ++i ) {
          char c = test.charAt( i );
          int i = (int) c;
          System.out.println(i);
          }
    integer to boolean  b = (i != 0);boolean to integer  i = (b)?1:0;note :To catch illegal number conversion, try using the try/catch mechanism. try{
      i = Integer.parseInt(aString);
      }
    catch(NumberFormatException e)
      {
      }
      

  4.   

    你用的jdk是多高版本?我用jdk1.2.2没有问题。
      

  5.   

    to:zh9625(短笛)
    我也试过,以前我也是这样用的,也没有问题,不知道是为什么?
    to:packy_li():
    我的jdk是1.3.1我把有问题的代码贴出来,大家帮我看看吧,谢了!!package dbconnection;import java.sql.*;public class Page
    {
    private ResultSet rs;
    private int pageSize,recordCount = -1;
    private String commandText;
    private Statement stmt; public Page(Statement statement,String commandText,int pageSize)
    {
    this.stmt = statement;
    this.commandText = commandText;
    this.pageSize = pageSize;
    } public int getRecordCount() throws SQLException
    {
    StringBuffer tempSql = new StringBuffer("SELECT COUNT(*) ");
    int fromPos = commandText.toLowerCase().indexOf("from");
    tempSql.append(commandText.substring(fromPos));
    ResultSet rstemp = stmt.executeQuery(tempSql.toString());
    rstemp.next();
    int count = rstemp.getInt(1);
    rstemp.close();
    this.recordCount = count;
    return count;
    } public int getPageCount()  throws SQLException
    {
    if(this.recordCount == -1) this.recordCount = getRecordCount();
    return Math.ceil((double)recordCount/pageSize);//这里出错!
    } public ResultSet getPage(int currentPage)  throws SQLException
    {
    StringBuffer tempsql = new StringBuffer(commandText);
    int startIndex = (currentPage - 1) * pageSize;
    tempsql.append(" limit " + startIndex + "," + pageSize);
    return stmt.executeQuery(tempsql.toString());
    }
    }
      

  6.   

    public double getPageCount()  throws SQLException