package com.suypower.chengyu.csdn;
import java.text.DecimalFormat;
public class DoubleTest {
public static void main(String[] args)
{
DoubleTest dt = new DoubleTest();
double dou = dt.getDouble("123456.3456",2);
System.out.println(dou);
}
public double getDouble(String Dtr, int i)
{
double d = Double.parseDouble(Dtr);
DecimalFormat df = new DecimalFormat("##.##");
String str = df.format(d);
double result = Double.parseDouble(str);
return result;
}
}
//Java实现 字符串到实数转化的伪代码
//Public double GetDouble(
//String Dtr,//转换目标
//int len//小数位长度
//)
//Eg GetDouble(“123456.3456”,2) = 123456.35
java DecimalFormat
最新推荐文章于 2020-07-29 20:01:30 发布