日期:2014-05-20  浏览次数:20690 次

求类似于1/405.7682707的算法
如题:1/405.7682707=0.0024644608073344
如果使用科学表示法:2.4645e-3
不知道诸位可以帮忙写个方法得到这样的表达式。

Java code

public String getQuotient(double dividend,double divisor){

}




假如带入参数:
Java code

int value=(1,405.7682707)



这个时候value=2.4645e-3

谢谢各位的帮忙了!

------解决方案--------------------
科学计数法的整数只有 1 位,不可能会有两位的!

有两种方式,各有优缺点

Java code
import java.text.DecimalFormat;

public class Test01 {

    public static void main(String[] args) {
        String str = getQuotient(1, 405.7682707);
        System.out.println(str);
    }
    
    public static String getQuotient(double dividend,double divisor){
        // 这种方式的 E 只能是大写的
        // return new DecimalFormat("#.####E0").format(dividend / divisor);
        // 而这种方式如果指数小于 2 位数,会变成 e03 这样的
        return String.format("%.4e", dividend / divisor);
    }
}