随笔分类 -  Java.文本数字格式化

摘要:第一种是使用String.format("%04d",i),第二种使用new DecimalFormat("0000").format(i) 阅读全文
posted @ 2022-05-28 15:08 逆火狂飙 阅读(2640) 评论(0) 推荐(0)
摘要:%-10s 字符串定10位长,不够右补空格 %10s 字符串定10位长,不够左补空格 %-10d 数字定10位长, 不够右补空格 %10d 数字定10位长, 不够左补空格 总之,定长就是百分号后写几位,右补有中划线,左补没有。 END 阅读全文
posted @ 2021-12-30 21:35 逆火狂飙 阅读(724) 评论(0) 推荐(1)
摘要:String的format语法搭配转化符,在格式化输出方面效果特别好,值得掌握。 例程: System.out.println(" C1 | C2 | C3 |"); int a=10,b=20,c=30; String str=String.format("%10s%10s%10s",a,b,c) 阅读全文
posted @ 2020-03-21 08:29 逆火狂飙 阅读(438) 评论(0) 推荐(0)
摘要:package com.testEmp; import java.text.DecimalFormat; public class NumberFormat { public static void main(String[] args) { System.out.println(toWestNum 阅读全文
posted @ 2019-10-04 21:31 逆火狂飙 阅读(2310) 评论(0) 推荐(0)
摘要:介绍一种实用精确的正五边形作法。 阅读全文
posted @ 2014-11-21 06:51 逆火狂飙 阅读(319) 评论(0) 推荐(0)
摘要:请参考下面函数: public static String round2DecimalPlaces(double d){ java.text.DecimalFormat df =new java.text.DecimalFormat("#0.00"); return df.format(d); } 阅读全文
posted @ 2013-09-18 19:35 逆火狂飙 阅读(538) 评论(0) 推荐(0)