• Post Reply Bookmark Topic Watch Topic
  • New Topic

adding dot to int

 
Tai Yo
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As I asked in my previous post, I am getting numerical data from jTextArea and splitting them based on column.
The next purpose that I want to achieve is I want to add "." ->dot after numbers (reason is Fortran format).
As you can see from the following example "." were added in 1st and 2nd column, i.e. "." should be added to int, if there are double and float must be skipped.

By using the answer of @Winston I have added dot -> "%11s.", but it adds for all numbers:

I have searched from Internet, but couldn't find reliable solution.
I would like to ask, how can I add "." dot to integers by skipping double and float numbers?
Any help would be much appreciated.
 
Campbell Ritchie
Marshal
Posts: 52586
119
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can create a Scanner with a String to scan, like this:-edit: Change : . to : "" because of mistake.
 
Tai Yo
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell you are G.R.E.A.T (Grateful, Respect, Effulgent, Action, Thanks)!!
 
Campbell Ritchie
Marshal
Posts: 52586
119
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Gee, shucks, you got me all embarrassed! It's a pleasure.
 
Campbell Ritchie
Marshal
Posts: 52586
119
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Remember that Double.parseDouble("123") or BigInteger.valueOf("123") or similar will create floating‑point numbers with no figures after the decimal point, but new Scanner("123").hasNextInt() will return true.
 
Tai Yo
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for clarification, I will take into account.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!