954,510 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

How to write FNVAL functions

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

bsridhar
Newbie Poster
2 posts since Jun 2004
Reputation Points: 10
Solved Threads: 0
 
... 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:[indent] Double.valueOf(String) [/indent][indent] Long.valueOf(String) [/indent]
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.

... 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 bedifferent (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.

gusano79
Posting Pro
521 posts since May 2004
Reputation Points: 182
Solved Threads: 77
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You