01: /*
02: * DoubleFix.java
03: *
04: * Copyright 1997 Massachusetts Institute of Technology.
05: * All Rights Reserved.
06: *
07: * Author: Ora Lassila
08: *
09: * $Id: DoubleFix.java,v 1.2 1998/01/22 13:08:46 bmahe Exp $
10: */
11:
12: package org.w3c.tools.sexpr;
13:
14: public class DoubleFix {
15:
16: /**
17: * A fix for Double.valueOf in JDK 1.0.2
18: */
19: public static Double valueOf(String rep) // Double.valueOf is buggy in 1.0.2
20: throws NumberFormatException {
21: String s = rep.trim();
22: int point = s.indexOf('.');
23: if (point == -1)
24: throw new NumberFormatException();
25: double whole = 0;
26: if (point > 0)
27: whole = (double) Integer.parseInt(s.substring(0, point));
28: double fraction = 0;
29: if (point < s.length() - 1)
30: fraction = (double) Integer
31: .parseInt(s.substring(point + 1));
32: else if (point == 0 || !Character.isDigit(s.charAt(point + 1)))
33: throw new NumberFormatException();
34: int m;
35: for (m = 10; m < fraction; m *= 10)
36: ;
37: return new Double(whole + fraction / (double) m);
38: }
39:
40: }
|