How to write FNVAL functions

Reply

Join Date: Jun 2004
Posts: 2
Reputation: bsridhar is an unknown quantity at this point 
Solved Threads: 0
bsridhar bsridhar is offline Offline
Newbie Poster

How to write FNVAL functions

 
0
  #1
Jun 18th, 2004
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
Reply With Quote Quick reply to this message  
Join Date: May 2004
Posts: 80
Reputation: gusano79 is on a distinguished road 
Solved Threads: 5
gusano79 gusano79 is offline Offline
Junior Poster in Training

Re: How to write FNVAL functions

 
0
  #2
Jun 24th, 2004
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.

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.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC