Skip to content

Instantly share code, notes, and snippets.

@stephenh
Created November 3, 2013 23:53
Show Gist options
  • Select an option

  • Save stephenh/7296159 to your computer and use it in GitHub Desktop.

Select an option

Save stephenh/7296159 to your computer and use it in GitHub Desktop.
package temp;
import java.math.BigDecimal;
import java.math.BigInteger;
public class Test {
public static void main(String[] args) {
System.out.println(toSeventeenDigits(1000));
System.out.println(toSeventeenDigits(100));
System.out.println(toSeventeenDigits(10));
System.out.println(toSeventeenDigits(1));
}
private static String toSeventeenDigits(long l) {
BigDecimal d = new BigDecimal(BigInteger.valueOf(l), 17);
d = d.divide(new BigDecimal(10).pow(17));
return d.toPlainString();
}
}
0.0000000000000000000000000000001
0.00000000000000000000000000000001
0.000000000000000000000000000000001
0.0000000000000000000000000000000001
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment