字符串的分数,转成分子分母相除的小数

字符串的分数,转成分子分母相除的小数

String attribute3 = "1/4";
if (attribute3 != null && attribute3.length() > 0) {
int index = attribute3.indexOf('/');
double x1 = Double.parseDouble(attribute3.substring(0,
index));
double x2 = Double.parseDouble(attribute3
.substring(index + 1));
System.out.println(x1 / x2);
double toBeString = x1 / x2;
String valueOf = String.valueOf(toBeString);
attribute3 = valueOf;
}
 
posted @ 2023-06-21 14:55  爱豆技术部  阅读(10)  评论(0编辑  收藏  举报
TOP