1.数字格式化

  使用Java.text.DecimalFormat格式化数字,一般使用其中的DecimalFormat类。如:

import java.text.DecimalFormat;
public class DecimalFormatdemo{
    static public void simpleformat(String pattern,double value){
        DecimalFormat myformat=new DecimalFormat(pattern);
        String out=myformat.format(value);
        System.out.println(value+" "+pattern+" "+out);
    }
    public static void main(String[] args){
        simpleformat("###,###.###",123456.789);
    }
}    

  学会查看DecimalFormat类的其他方法进行格式化处理。

2.数字运算

2.1 Math类

  如:Math.数学方法(三角函数、指数函数、取整、最大最小值、绝对值)

2.2 随机数:Math.random()方法

2.3 Random类

  需要import java.util.Random;该类用来产生各种基本类型的随机数,如:nextInt()、nextDouble()等方法。

2.4 大数字运算BigInteger、BigDecimal类

  由于基本类型Int的最大值为2的31次方减1,如果要计算更大的数字,引入了BigInteger类。使用时,需要import java.math.Biginteger(BigDecimal)。

    api文档:http://docs.oracle.com/javase/7/docs/api/

  

 

相关文章:

  • 2021-10-27
  • 2021-09-21
  • 2021-05-15
  • 2021-04-25
  • 2021-04-29
  • 2021-05-22
  • 2021-12-20
  • 2021-07-30
猜你喜欢
  • 2021-07-06
  • 2021-10-17
  • 2021-09-06
  • 2021-11-28
  • 2022-12-23
  • 2021-10-17
  • 2021-12-13
相关资源
相似解决方案