GIDForums  

Go Back   GIDForums > Computer Programming Forums > Java Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 09-Oct-2005, 23:32
clara clara is offline
New Member
 
Join Date: Oct 2005
Posts: 9
clara is on a distinguished road

How to read scientific number from file using java


Hi I'm a new member here...and I've posted similar question in the C++ forum.

I'm not very good in programming, but currently I have a task of doing a set of programming in both java and C++ for handling VRML files as input.

Currently I'm having one problem (actually I have lots of problem, but that got to do with the algorithms *groan*), which is to read a scientific number (for example: -1.26759e-006).
In my program, when I know I need to read a number, I would read the string read from file as 'float'.
But then I came across an input file where some of the numbers are scientific numbers, and my program returns an error.

I don't know how to recognize a scientific number (when the program 'sees' one) and how to handle it..

I need help m(_ _)m
Thank you for your advice..I'd really appreciate it
  #2  
Old 10-Oct-2005, 00:22
fortytwo fortytwo is offline
New Member
 
Join Date: Oct 2005
Posts: 3
fortytwo is on a distinguished road

Re: How to read scientific number from file using java


I don't think there is a standard Java method to read scientific notation numbers.

But you may always parse it yourself with some simple code using StringTokenizer.

If you want you may write a finite state machine for the parsing (a lot nicer) but I guess that for your simple needs StringTokenizer + some Double.parseDouble is ok. Shouldn't take more than 1/2 hour to finish the method.
  #3  
Old 10-Oct-2005, 03:07
clara clara is offline
New Member
 
Join Date: Oct 2005
Posts: 9
clara is on a distinguished road

Re: How to read scientific number from file using java


If using StringTokenizer, then I need to separate the 2 parts in the scientific number using 'e' as deliminator. Is this what you meant?

I'm still confused as to how to handle the numbers, though...but I will try it out thank you for the suggestion
  #4  
Old 10-Oct-2005, 03:10
fortytwo fortytwo is offline
New Member
 
Join Date: Oct 2005
Posts: 3
fortytwo is on a distinguished road

Re: How to read scientific number from file using java


Well, you just read the 2 numbers with Double.parseDouble().
So you have

Number1 e Number2

And you just do something like

JAVA Code:
Double.parseDouble(number1) * Math.pow(10,Double.parseDouble(Number2))
  #5  
Old 10-Oct-2005, 20:51
clara clara is offline
New Member
 
Join Date: Oct 2005
Posts: 9
clara is on a distinguished road

Re: How to read scientific number from file using java


I see I see....thank you so much for the help
 
 

Recent GIDBlogWelcome to Baghdad by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Airport Log program using 3D linked List : problem reading from file batrsau C Programming Language 11 29-Feb-2008 07:44
How to read scientific number from file? clara C Programming Language 7 11-Oct-2005 02:24
Made program in Java, trying C++ now, file i/o problems technickel C++ Forum 4 19-Feb-2005 00:32
Yet another CD burner problem: Lite-On LSC-24082K Erwin Computer Hardware Forum 1 22-May-2004 11:28

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 00:42.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.