C#:STRING.FORMAT数字格式化输出 1.各种常用数字格式化 货币转换 C 或 c(默认小数点后2位.C3后面跟的数字就代表小数后几位) string.Format("{0:C}",a)<==>a.ToString("C")//$2.50 string.Format("{0:C3}",a)<==>a.ToString("C3")//$2.500 转换为十进制数 D 或 d a=25
一.Math类 Math类常用的方法: public static long abs (double a) 返回a的绝对值 public static double max (double a,double b) 返回a.b的最大值 public static double min (double a,double b) 返回a.b的最小值 public static double pow (double a,double b) 返回a的b次幂 public static double sqrt
public class StringFormatDemo { public static void main(String[] args) { //String.format 实现了四舍五入 System.out.println(String.format("%.2f",8.1256));//8.13 System.out.println(String.format("%.2f",8.1216));//8.12 System.out.println(String.