如题!

解决方案 »

  1.   

    function a() {
      var n = new Number(document.all.xx.value);
      n = Math.round(n*100)/100;
      document.all.xx.value = n;
    }
      

  2.   

    java.text.DecimalFormat df =new java.text.DecimalFormat("#.00"); 
    String aveprice=df.format(avprice);
      

  3.   

    同意楼上的:
    java.text.DecimalFormat df =new java.text.DecimalFormat("0.00"); 
    String aveprice=df.format(avprice);
      

  4.   

    alert((document.all.xx.value).toFixed(2));
      

  5.   

    java.text.DecimalFormat df =new java.text.DecimalFormat("#.00");
    String aveprice=df.format(avprice);
      

  6.   

    lz的文本框是html里边的还是图形界面的?
      

  7.   

    "
    java.text.DecimalFormat df =new java.text.DecimalFormat("#.00"); 
    String aveprice=df.format(avprice);
    "怎么用呀?能说的详细一点儿吗? 急等....
      

  8.   

    四舍五入我们的第一个反应是做四舍五入。Math类中的round方法不能设置保留几位小数,我们只能象这样(保留两位):public double round(double value){return Math.round(value*100)/100.0;}非常不幸,上面的代码并不能正常工作,给这个方法传入4.015它将返回4.01而不是4.02,如我们在上面看到的4.015*100=401.49999999999994因此如果我们要做到精确的四舍五入,不能利用简单类型做任何运算java.text.DecimalFormat也不能解决这个问题:System.out.println(new java.text.DecimalFormat("0.00").format(4.025));输出是4.02
      

  9.   

    double avprice=Double.parseDouble(request.getParameter("avprice"));
    或是
    double avprice=234.5678;
    java.text.DecimalFormat df =new java.text.DecimalFormat("#.00");
    String aveprice=df.format(avprice);
      

  10.   

    那就用Sunny319(努力学习java中.) 的方法,在javaScript 中做:
    document.fieldname.value = (document.fieldname.value).toFixed(2)
      

  11.   

    试试这个方法吧 /**
    * 提供精确的小数位四舍五入处理。
    * @param v 需要四舍五入的数字
    * @param scale 小数点后保留几位
    * @return 四舍五入后的结果
    */
    public static double round(double v, int scale) {
    if (scale < 0) {
    throw new IllegalArgumentException("The scale must be a positive integer or zero");
    }
    BigDecimal b = new BigDecimal(Double.toString(v));
    BigDecimal one = new BigDecimal("1");
    return b.divide(one, scale, BigDecimal.ROUND_HALF_UP).doubleValue();
    }
      

  12.   

    有在 jsp 中的例子吗?
      

  13.   

    java.text.DecimalFormat df =new java.text.DecimalFormat("#.00"); 
    String aveprice=df.format(avprice);
      

  14.   

    人家是说在 javascript 吧, 有些人还大把大把的写java代码.
      

  15.   

    var inputValue=document.all('inputname').value;
    var base = Math.pow(10,exp);
    var mutil = inputValue*base;
    var roundValue = Math.round(mutil)/base;
      

  16.   

    var exp=2;//保留小数位
    var inputValue=document.all('inputname').value;
    var base = Math.pow(10,exp);
    var mutil = inputValue*base;
    var roundValue = Math.round(mutil)/base;