File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Formatting a BigInteger Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "Formatting a BigInteger" Watch "Formatting a BigInteger" New topic
Author

Formatting a BigInteger

Luigi Plinge
Ranch Hand

Joined: Jan 06, 2011
Posts: 441

Hi,

I've searched the interwebs but can't find how to format the output of a BigInteger with commas.

If it were an integer I'd do



but I'm not sure how to do it for a BigInteger (or a long for that matter).
Mike Simmons
Ranch Hand

Joined: Mar 05, 2008
Posts: 2770
    
    2
Have you tried using the exact same code?

This is a subtle point, but when the JavaDocs for Formatter talk about "integer" or "integral" types, they don't just mean int. The term actually includes byte, short, int, long, all the wrapper classes for those primitive types, and BigInteger. In short, all standard numeric data types in Java except those for floating-point numbers. So 'd' can be applied to all of these.
Luigi Plinge
Ranch Hand

Joined: Jan 06, 2011
Posts: 441

Wow, it works! I'm reading Head First Java and it doesn't mention longs or BigIntegers.

Thanks!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Formatting a BigInteger
 
Similar Threads
BigInteger exponents - how?
Why no toBinaryString(BigInteger b)
Convert an int to a BigInteger
BigInteger Power/Exponent BigInteger
user defined data type