【发布时间】:2014-03-04 01:35:39
【问题描述】:
我一直在尝试移植一段 JavaScript 代码,而现在,我还没有开始工作的唯一部分出现了这个错误:无法在原始类型 int 上调用 padLz(int) 。下面是原始的 JavaScript 代码,同样是我的移植版本,我还不能开始工作的部分突出显示。
错误:
无法在原始类型 int 上调用 padLz(int)
有人知道修复方法吗?
原创
OsGridRef.prototype.toString = function(digits) {
digits = (typeof digits == 'undefined') ? 10 : digits;
e = this.easting, n = this.northing;
if (e==NaN || n==NaN) return '??';
// get the 100km-grid indices
var e100k = Math.floor(e/100000), n100k = Math.floor(n/100000);
if (e100k<0 || e100k>6 || n100k<0 || n100k>12) return '';
// translate those into numeric equivalents of the grid letters
var l1 = (19-n100k) - (19-n100k)%5 + Math.floor((e100k+10)/5);
var l2 = (19-n100k)*5%25 + e100k%5;
// compensate for skipped 'I' and build grid letter-pairs
if (l1 > 7) l1++;
if (l2 > 7) l2++;
var letPair = String.fromCharCode(l1+'A'.charCodeAt(0), l2+'A'.charCodeAt(0));
// strip 100km-grid indices from easting & northing, and reduce precision
e = Math.floor((e%100000)/Math.pow(10,5-digits/2));
n = Math.floor((n%100000)/Math.pow(10,5-digits/2));
var gridRef = letPair + ' ' + e.padLz(digits/2) + ' ' + n.padLz(digits/2);
return gridRef;
}
// pad a number with sufficient leading zeros to make it w chars wide
Number.prototype.padLZ = function(w) {
var n = this.toString();
for (var i=0; i<w-n.length; i++) n = '0' + n;
return n;
}
移植版
public String gridrefNumToLet(int e, int n, int digits) {
// get the 100km-grid indices
double e100k = Math.floor(e/100000), n100k = Math.floor(n/100000);
if (e100k<0 || e100k>6 || n100k<0 || n100k>12) return null;
// translate those into numeric equivalents of the grid letters
double l1 = (19-n100k) - (19-n100k)%5 + Math.floor((e100k+10)/5);
double l2 = (19-n100k)*5%25 + e100k%5;
// compensate for skipped 'I' and build grid letter-pairs
if (l1 > 7) l1++;
if (l2 > 7) l2++;
String letPair = String.valueOf(l1+"A".charAt(0))+ String.valueOf(l2+"A".charAt(0));
// strip 100km-grid indices from easting & northing, and reduce precision
e = (int) Math.floor((e%100000)/Math.pow(10,5-digits/2));
n = (int) Math.floor((n%100000)/Math.pow(10,5-digits/2));
字符串 gridRef = letPair + ' ' + e.padLz(digits/2) + ' ' + n.padLz(digits/2);
return gridRef;
}
// pad a number with sufficient leading zeros to make it w chars wide
public String padLZ(String w) {
String n = this.toString();
for (int i=0; i< n.length(); i++) n = '0' + n;
return n;
}
【问题讨论】:
-
原语没有方法。 padLz 是做什么的?
-
我已经解释过了,上面放了代码
标签: java javascript android eclipse android-activity