943,649 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Unsolved
  • Views: 3570
  • Java RSS
Jun 18th, 2004
0

How to write FNVAL functions

Expand Post »
Dear sir,


This function converts a string to a numeric value. Provide two versions of this function overloading to return either a long or double value

Here is the pseudo code for the FNVAL processing

Validate the input string value
If it contains any non numeric characters, then throw a CSResult
Convert the string value and return either a long or a double result

please how to write the overload functions same parameter(passing only string) and returtype either double and long.


Thanks&regard
Sridhar
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
bsridhar is offline Offline
2 posts
since Jun 2004
Jun 24th, 2004
0

Re: How to write FNVAL functions

Quote originally posted by bsridhar ...
...
This function converts a string to a numeric value.
...
Are you interested in writing the conversion yourself, or do you just need the conversion to happen? These can help:
Double.valueOf(String)
Long.valueOf(String)
One approach would be to first try to convert the string to a long. If it works, then you have an integer. If it fails (i.e. throws an exception), then try to convert it to a double--maybe it was only a decimal point that caused the long conversion to fail. Success means it's a double, failure indicates a non-number string. After that, you'll have a long, a double or something that is neither, and you can do what you want with it.

Quote originally posted by bsridhar ...
...
please how to write the overload functions same parameter(passing only string) and returtype either double and long.
...
You're asking for something that doesn't exist. Parameters for overloaded methods must always be different (number or type of params), and the return type must always be the same. You'll have to come up with some other way to handle the multiple types.
Reputation Points: 182
Solved Threads: 71
Posting Pro in Training
gusano79 is offline Offline
475 posts
since May 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: Vending machine
Next Thread in Java Forum Timeline: Internal frames





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC