java本身自带一些封装好的类方便数字问题的处理,review下方便以后使用
DecimalFormat类 可格式化数字格式,控制输出格式
Math类 提供三角函数、指数函数、取整函数、最大最小函数、随机数等方法,方便运算
BigInteger类 提供大整数运算操作
BigDecimal类 提供大浮点数运算操作
package re04; import java.text.DecimalFormat; import java.lang.Math; import java.math.*; /** * Description: 数字类处理 * * @author weber DateTime 2017年3月20日 下午6:24:03 */ public class DigitalTest { //DecimalFormat 样例 public static String tryFormat(String s, int value){ DecimalFormat myFormat = new DecimalFormat(s); String ans = myFormat.format(value); return ans; } //Math样例 public static void tryMath() { double res = Math.sin(Math.PI/2); res= 1 + Math.log10(res); res = Math.pow(res,res); System.out.println(Math.rint(res)); } //Random样例 public static void tryRandom() { int s=(int)(Math.random()*5); System.out.println(s); } //BigInteger样例 public static void tryBigInteger() { BigInteger t = new BigInteger("123456789"); System.out.println(t.multiply(t)); } public static void main(String[] args){ String s="###,###,###"; System.out.println(tryFormat(s,123456789)); tryMath(); tryRandom(); tryBigInteger(); } }