• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Format String in commas

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How do I format a string with commas to display in curreny format?
Assume the incoming string is a big number. For example, "1234567901234567890123456"

I want result as "12,345,678,901,234,567,890,123,456"

The DecimalFormat in Java has a limitation to format a big number.

Thanks.
 
Ranch Hand
Posts: 1608
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


...
Assume the incoming string is a big number.
...
The DecimalFormat in Java has a limitation to format a big number.



95% of problems are solved by clarifying your requirements. Let's filter out the things that are definitely not requirements. "incoming string is a big number" - that statement can never hold true. Is it a String? If yes, then it's a String, and never a number. This distinction is important. I'll assume that the answer to this question is "yes".

Now that you have a String, why are you using a DecimalFormat? What does a String have to do with a decimal number formatter? Nothing related to the problem that you are trying to solve. I'll leave the determination of the correct approach to solve your problem up to you - after all, my speculations at your requirements may not be correct.

To reiterate, here are the things that are definitely incorrect:
- You have a String, that is a big number"
- DecimalFormat has an issue with "big numbers" - an unsubstantiated conclusion drawn on a false basis of understanding.

Good luck.
 
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There's probably something much better than this, but here's a couple of options

reply
    Bookmark Topic Watch Topic
  • New Topic