Here you can find the source of doubleToSz(double dval)
public static String doubleToSz(double dval)
//package com.java2s; //License from project: Open Source License import java.text.*; import java.util.*; import java.text.*; public class Main { /**/*from w w w .j a v a 2s .c om*/ *Converts double into a formatted string representation */ public static String doubleToSz(double dval) { String szexp; double dtempval = dval; int nexp = 0; NumberFormat nf2 = NumberFormat.getInstance(Locale.ENGLISH); nf2.setMinimumFractionDigits(2); nf2.setMaximumFractionDigits(2); NumberFormat nf1 = NumberFormat.getInstance(Locale.ENGLISH); nf1.setMinimumFractionDigits(1); nf1.setMaximumFractionDigits(1); if (dval <= 0) { szexp = "0.00"; } else { while ((dtempval < 0.995) && (dtempval > 0)) { nexp--; dtempval = dtempval * 10; } if (nexp < -2) { dtempval = Math.pow(10, Math.log(dval) / Math.log(10) - nexp); szexp = nf1.format(dtempval) + "E" + nexp; } else { szexp = nf2.format(dval); } } return szexp; } }