• Post Reply Bookmark Topic Watch Topic
  • New Topic

StreamTokenizer  RSS feed

 
Mandy Rogers
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?
------------------------------------------------------------------
 
Tony Docherty
Bartender
Posts: 3271
82
  • 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.
 
Paweł Baczyński
Bartender
Posts: 2074
44
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.
 
Dave Tolls
Ranch Foreman
Posts: 3056
37
  • 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: 3271
82
  • 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.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!