@
douleL 简单写了一段试了下了 js 能对应上,但是精度是个大问题,无法模拟 js 的精度丢失,感觉 java 的 double 精度比 js 小,bigDecimal 精度又太大,
@
Test public void testRadix() {
assertEquals("0.o72tt3lcjtq", toString("0.6721285152844136", 36));
}
public String toString(String number, int radix) {
BigDecimal N = new BigDecimal(number);
StringBuilder sb = new StringBuilder();
BigInteger i = N.toBigInteger();
sb.append(i.toString(radix));
sb.append('.');
while(new BigDecimal(N.intValue()).compareTo(N) != 0 && sb.length() < 13) {
N = N.multiply(new BigDecimal(radix));
i = N.toBigInteger().mod(new BigDecimal(radix).toBigInteger());
sb.append(i.toString(radix));
}
return sb.toString();
}