java数字的格式化
1) 格式化整数(把浮点数转化为整数)
NumberFormat nf = NumberFormat.getIntegerInstance();
double v=12.6;
System.out.println(nf.format(v));
输出结果13,因为自动舍入的。
2)格式化浮点数(保留两位小数,自动进位,负数也可以)
方法一:
DecimalFormat df=new DecimalFormat("#.##");
double v=12.126;
String s=df.format(v);
System.out.println(s);
输出的结果为:12.13
方法二:
double v=-32.126;
String s=v+"";
System.out.println(s.substring(0, s.indexOf(".")+3));
(不推荐使用此方法,因为如果原数不存在小数点或者小数点后只有1为会有异常)
3) 格式化浮点数(变为xx%形式)
NumberFormat nf = NumberFormat.getPercentInstance();
double s=0.6145;
System.out.println(nf.format(s));
输出61%
相关文档:
public class test {
public static void main(String argv[]) {
try {
Runtime.getRuntime().exec("cmd /c del F:\\aaa.txt");
} catch (Exception e) {
& ......
package com.ghb.crp.file;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutput ......
Java上的宝石 JRuby 1.5正式发布
2010年05月12日,JRuby团队非常高兴的宣布1.5.0版的发布。在这之前,曾经发布过JRuby 1.5.0 RC1的发布消息,相比之下,正式发布本本又提供了很多更新。
JRuby 1.5.0 版本的主页和下载地址分别是:
主页:http://www.jruby.org/
下载:http://www.jruby.org/download
这次发布是JRuby历 ......
System.out.println(System.getProperty("java.version")); //java版本号
System.out.println(System.getProperty("java.vendor")); //Java提供商名称
System.out.println(System.getProperty("java.vendor.url")); //Java提供商网站
System.out.println( ......