/* File: DasNumberFormatter.java * Copyright (C) 2002-2003 The University of Iowa * Created by: Jeremy Faden * Jessica Swanner * Edward E. West * * This file is part of the das2 library. * * das2 is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ /** * * @author jessica */ package org.das2.graph; import java.text.DecimalFormat; public class DasNumberFormatter { /** Creates a new instance of DecFormat */ public DasNumberFormatter() { } /** * @param args the command line arguments */ public static void main(String[] args) { DecimalFormat dFormatter = new DecimalFormat(); DecimalFormat dF = new DecimalFormat(); String result; double [] b = {123.123, 12.1234, 1.2345, 1234.12, 123.1}; dFormatter = createDF(b); for(int i=0; i max_Num) max_Num = testNum; //if length of current fracDigit is larger than max, set max to current length if(len_fracDigits > max_fracVal) max_fracVal=len_fracDigits; intDigits = value[i].substring(0, index); //String of beginning integer digits of # len_intDigits = intDigits.length(); //get the length of String of integer digits //if length of current intDigit is larger than max, set max to current length if(len_intDigits > max_intVal) max_intVal=len_intDigits; }//for (int i=0; i last.length()){ last = last + 0; }//while myPattern = "###." + last; decFormat = new DecimalFormat(myPattern); }//if (max_fracVal < 5) //if the largest fractional digit in series is 0, then return pattern ###, //ex. 1.0 will be 1, 10.0 will be 10, it will drop unneeded decimal point and trailing 0 if(max_Num == 0){ myPattern = "###"; decFormat = new DecimalFormat(myPattern); }//(max_Num == 0) //scientific notation int newMax = len_intDigits + len_fracDigits; if(max_intVal > 5){ String subPattern = ""; for(int k=0; k<=newMax; k++){ subPattern = subPattern + '#'; if(newMax==3) subPattern = subPattern + '.'; }//for(int k=0; k<==nexMax; k++) //myPattern = subPattern; myPattern = "###.####E0"; decFormat = new DecimalFormat(myPattern); decFormat.setMaximumIntegerDigits(2); decFormat.setMinimumIntegerDigits(2); }//if(max_intVal > 5) return decFormat; }//static DecimalFormat createDF (double [] a) static final double LOG_10 = Math.log(10); static DecimalFormat makeNewDF(double [] a){ DecimalFormat df = new DecimalFormat(); int len_a = a.length; int first; double intBase, fracBase, digit, second; for(int k=0; k