-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from umjammer/0.0.9
0.0.9
- Loading branch information
Showing
14 changed files
with
109 additions
and
115 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,21 +18,20 @@ | |
* @author <a href="mailto:[email protected]">Naohide Sano</a> (nsano) | ||
* @version 0.00 050408 nsano ported from mdbtool <br> | ||
*/ | ||
public class Currency { | ||
class Currency { | ||
|
||
/** */ | ||
private static final int MAXPRECISION = 20; | ||
private static final int MAX_PRECISION = 20; | ||
|
||
/** */ | ||
public static String mdb_money_to_string(MdbFile mdb, int start) { | ||
public static String moneyToString(byte[] buffer, int start) { | ||
final int numberOfBytes = 8; | ||
byte[] b = new byte[numberOfBytes]; | ||
System.arraycopy(mdb.getPageBuffer(), start, b, 0, numberOfBytes); | ||
System.arraycopy(buffer, start, b, 0, numberOfBytes); | ||
|
||
String s; | ||
int[] multiplier = new int[MAXPRECISION]; | ||
int[] temp = new int[MAXPRECISION]; | ||
int[] product = new int[MAXPRECISION]; | ||
int[] multiplier = new int[MAX_PRECISION]; | ||
int[] temp = new int[MAX_PRECISION]; | ||
int[] product = new int[MAX_PRECISION]; | ||
|
||
int negative = 0; | ||
|
||
|
@@ -54,67 +53,57 @@ public static String mdb_money_to_string(MdbFile mdb, int start) { | |
|
||
b[7] = 0; | ||
for (int pos = 0; pos < numberOfBytes; pos++) { | ||
multiply_byte(product, b[pos] & 0xff, multiplier); | ||
multiplyByte(product, b[pos] & 0xff, multiplier); | ||
|
||
System.arraycopy(multiplier, 0, temp, 0, MAXPRECISION); | ||
System.arraycopy(multiplier, 0, temp, 0, MAX_PRECISION); | ||
Arrays.fill(multiplier, 0); | ||
multiply_byte(multiplier, 256, temp); | ||
multiplyByte(multiplier, 256, temp); | ||
} | ||
if (negative != 0) { | ||
s = "-" + array_to_string(product, 4); | ||
} else { | ||
s = array_to_string(product, 4); | ||
} | ||
return s; | ||
return ((negative != 0) ? "-" : "") + arrayToString(product, 4); | ||
} | ||
|
||
private static int multiply_byte(int[] product, int num, int[] multiplier) { | ||
int[] number = new int[3]; | ||
int i, top, j, start; | ||
|
||
number[0] = num % 10; | ||
number[1] = (num / 10) % 10; | ||
number[2] = (num / 100) % 10; | ||
|
||
for (top = MAXPRECISION - 1; top >= 0 && multiplier[top] == 0; top--) | ||
; | ||
start = 0; | ||
for (i = 0; i <= top; i++) { | ||
for (j = 0; j < 3; j++) { | ||
private static void multiplyByte(int[] product, int num, int[] multiplier) { | ||
int[] number = new int[] { | ||
num % 10, | ||
(num / 10) % 10, | ||
(num / 100) % 10 | ||
}; | ||
|
||
int top = MAX_PRECISION - 1; | ||
while (top >= 0 && multiplier[top] == 0) | ||
top--; | ||
int start = 0; | ||
for (int i = 0; i <= top; i++) { | ||
for (int j = 0; j < 3; j++) { | ||
product[j + start] += multiplier[i] * number[j]; | ||
} | ||
do_carry(product); | ||
doCarry(product); | ||
start++; | ||
} | ||
return 0; | ||
} | ||
|
||
private static int do_carry(int[] product) { | ||
int j; | ||
|
||
for (j = 0; j < MAXPRECISION; j++) { | ||
private static void doCarry(int[] product) { | ||
for (int j = 0; j < MAX_PRECISION; j++) { | ||
if (product[j] > 9) { | ||
product[j + 1] += product[j] / 10; | ||
product[j] = product[j] % 10; | ||
} | ||
} | ||
return 0; | ||
} | ||
|
||
static String array_to_string(int[] array, int scale) { | ||
int top, i, j; | ||
|
||
for (top = MAXPRECISION - 1; top >= 0 && top > scale && array[top] == 0; top--) | ||
; | ||
private static String arrayToString(int[] array, int scale) { | ||
int top = MAX_PRECISION - 1; | ||
while (top >= 0 && top > scale && array[top] == 0) | ||
top--; | ||
|
||
if (top == -1) { | ||
return "0"; | ||
} | ||
|
||
j = 0; | ||
int j = 0; | ||
char[] s = new char[100]; | ||
// TODO find a better number | ||
for (i = top; i >= 0; i--) { | ||
for (int i = top; i >= 0; i--) { | ||
if (top + 1 - j == scale) | ||
s[j++] = '.'; | ||
s[j++] = (char) (array[i] + '0'); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.