Win a copy of OCP Java SE 8 Programmer II Exam Study Guide this week in the OCP forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

StreamTokenizer  RSS feed

 
Greenhorn
Posts: 2
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you please tell me why StreamTokenizer makes my double numbers like 2.53 into two separate 2.0 and  53.0?
And how can i fix it so it gives me full number read from file?
------------------------------------------------------------------
 
Bartender
Posts: 3306
86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's a long time since I used StreamTokenizer I normally use Scanner these days, but I've just knocked up a quick demo on my system and it does correctly parse doubles.

It's probably something to do with the separator you are using, on my system it requires a '.' but I'm not sure if this is locale dependant.
I suggest you try printing out each token to see what token it is finding in your floating point number and also print out the numeric value of the character to make sure it is the '.' from the ascii set ie 46.
 
Bartender
Posts: 2155
46
Firefox Browser IntelliJ IDE Java Linux Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Tony Docherty wrote:It's probably something to do with the separator you are using, on my system it requires a '.' but I'm not sure if this is locale dependant.


My quick demo showed it is not locale dependant.
 
Rancher
Posts: 3385
38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Which parts of that code are producing the problem results?

Can you narrow it down for us?
 
Tony Docherty
Bartender
Posts: 3306
86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In your previous thread you showed a text file with ',' separators. I don't know if this is the file you are parsing but if it is then from Pawel's testing you will need to use '.' instead of ',' as the decimal separator.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!