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

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

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.