From 7164c8bbc9a53dd8cd995588ff600a8824eeb324 Mon Sep 17 00:00:00 2001 From: adash Date: Fri, 17 Apr 2009 19:04:15 +0000 Subject: [PATCH] test file for Double to String change --- Robust/src/Tests/TestDoubleToString.java | 66 ++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 Robust/src/Tests/TestDoubleToString.java diff --git a/Robust/src/Tests/TestDoubleToString.java b/Robust/src/Tests/TestDoubleToString.java new file mode 100644 index 00000000..ba4b1c73 --- /dev/null +++ b/Robust/src/Tests/TestDoubleToString.java @@ -0,0 +1,66 @@ +public class TestDoubleToString { + public TestDoubleToString() { + + } + public static void main(String args[]) { + TestDoubleToString td = new TestDoubleToString(); + double t = 35.21182666751214; + String test = td.alpha(t); + System.out.println("t= " + test); + t = t/ 10.0d; + test = td.alpha(t); + System.out.println("t= " + test); + } + + //function: converts a number into a string + String alpha(double value) + { + int i = 0, j = 0, k = 0; + long nodecimal = 0; + double decimal = 1.0d, valueA = 0.0d; + StringBuffer output = new StringBuffer(); + + for(i = 0; decimal != nodecimal; i++) + { + nodecimal = (long) (value*basePower(10, i)); + decimal = value*basePower(10, i); + } //i = place counted from right that decimal point appears + + valueA = nodecimal; //valueA = value with no decimal point (value*10^i) + + for(j = 0; decimal >= 0; j++) + { + nodecimal = (long) (valueA - basePower(10, j)); + decimal = (double) nodecimal; + } //j-1 = number of digits + + i--; + j--; + decimal = 0; + + for(k = j; k > 0; k--) + { + if(k == i) //if a decimal point was previously found + { //insert it where its meant to be + //output += (char)46; + output.append((char)46); + } + nodecimal = ((long) (valueA - decimal) / basePower(10, k-1)); + decimal += nodecimal*basePower(10, k-1); + //output += (char)(48 + nodecimal); + output.append((char)(48 + nodecimal)); + } + + System.out.println("output= " + output.toString()); + + return output.toString(); + } + + long basePower(int x, int y) { + long t = 1; + for(int i=0; i