• Post Reply Bookmark Topic Watch Topic
  • New Topic

Feeding a 42 digit number from a file to sum number datatype.  RSS feed

 
Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have written a program which takes a number in form of string, then parse it to a suitable data type.
Now the point is int and long are definitely not suitable.

here is the program or to be precise, its a snippet.


So I give input as "012345678901234567890123456789012345678901"
It gives me output as "7.0 7.0 7.0 7.0 7.0"

So now how to deal with this kind of situation, I am not asking anyone to debug this for me, but then provide with general outline.
P.S- This is not my home-work,assignment or anything else, I am a hobby programmer.
-Thank you.

 
Bartender
Posts: 1210
25
Android C++ Java Linux PHP Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

When you detect that the number has become too big for the primitive data types, then handle it as BigDecimal or BigInteger. Not sure what the goal of your program is - BigInteger or BigDecimal store huge numbers as strings and allow arithmetic ops on them.
 
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Karthik Shiraly wrote:... When you detect that the number has become too big for the primitive data types, then handle it as BigDecimal or BigInteger. Not sure what the goal of your program is...

Right. That's an awfully large number to treat as a number.
 
Marshal
Posts: 56610
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not a "beginning" topic. Moving thread.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!