Background
- 大多数计算器及计算机程序用科学记数法显示非常大和非常小的结果;
- 但很多时候,我们需要做一个统一,要么全部以科学计数法输出,要么就全部显示为普通计数。
- 注意:这里对大于等于1的数据做了特殊处理,为了保证输出的结果展示形式是统一的。

package com.yunlu.groundwater.constants;import com.yunlu.groundwater.gwParameters.entities.*;import java.util.HashMap;
import java.util.Map;public class Const {public static final String TPL_E1 = "%s+%s";public static final String FMT_DOUBLE = "0.00E00";
}
public static String scientificNotationString(Double val) {String res = new DecimalFormat(Const.FMT_DOUBLE).format(val);if (val >= 1) {int length = res.length();String prefix = res.substring(0, length-2);String suffix = res.substring(length-2, length);res = String.format(Const.TPL_E1, prefix, suffix);}return res;}