统计信息

  • 访问数:14586
  • 博客数:143
  • 建立时间:2008-01-05
  • 更新时间:2008-10-15
我叫王超然,是一名电脑爱好者,现在在新加坡留学上高一.我立志成为一名电脑人才,愿意在这里与大家一同分享我玩转电脑的心得.O-level华文考了A-One哈哈!

RoundOff

2008-01-16 23:30:47

天气: 晴朗 心情: 高兴

 

import java.util.Scanner;
class roundOffTest
{
  public static void main(String[] args)
  {

    Double output;
    Scanner scan = new Scanner(System.in);
     System.out.println("Please input a double: ");
    Double input = scan.nextDouble();
    if(((input*1000)%10)>=5)
      output = Math.ceil(input*100)/100;
      else
      output = Math.rint(input*100)/100;
      System.out.println("The final 2 decimal double is: "+output);
 
  }
}

import java.util.Scanner;
import java.text.DecimalFormat;
class roundoff2
{
  public static void main(String[] args)
  {
    Scanner scan = new Scanner(System.in);
    double input = scan.nextDouble();
    DecimalFormat df = new DecimalFormat("0.00");
    String output = df.format(input);//This is a String
    System.out.println(output);
  }
}

 


加入收藏 编辑 审核

TAG: computing

我来说两句

OPEN

Powered by X-Space 1.2 © 2001-2006 Comsenz Technology Ltd