This week's book giveaway is in the iOS forum.
We're giving away four copies of Classic Computer Science Problems in Swift and have David Kopec on-line!
See this thread for details.
Win a copy of Classic Computer Science Problems in Swift this week in the iOS forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Format String in commas  RSS feed

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • Quote
  • Report post to moderator
There's probably something much better than this, but here's a couple of options

 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!