We're a community of 1076K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,075,654 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

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

2
Contributors
1
Reply
6 Days
Discussion Span
8 Years Ago
Last Updated
2
Views
bsridhar
Newbie Poster
2 posts since Jun 2004
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 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: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.

gusano79
Practically a Master Poster
666 posts since May 2004
Reputation Points: 193
Solved Threads: 107
Skill Endorsements: 6

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
 
© 2013 DaniWeb® LLC
Page rendered in 0.0559 seconds using 2.66MB