Function to convert string to number

Hi there,
I wrote a function which converted a hor minute component of a date to a number. Now I need to do the same with a string (because the hours could be more then 23:95). Anyway here is my function. How can I rewrite it so it will accept a string as in parameter. Somwhow I can not work it out. Thanks a lot.
Chris
function calculate_hours_project(in_hours in DATE)
RETURN number
AS
hrs CHAR(2);
mins CHAR(2);
     BEGIN
          hrs := to_char(in_day, 'HH24');
          mins := to_char(in_day, 'MI');
          if hrs is not null and mins is not null then
          RETURN to_number(hrs + (mins/60));
          else
          RETURN 0;
          end if;
END calculate_hours_project;

Wouldn't it just be something like this?
sql>create or replace function calculate_hours_project(in_hours in varchar2)
  2  return number
  3  is
  4  begin
  5    return to_number(substr(in_hours, 1, instr(in_hours, ':') - 1)) +
  6           to_number(substr(in_hours, instr(in_hours, ':') + 1) / 60);
  7  end calculate_hours_project;
  8  /
Function created.
sql>select calculate_hours_project('08:05') from dual;
CALCULATE_HOURS_PROJECT('08:05')
                       8.0833333
1 row selected.
sql>select calculate_hours_project('35:34') from dual;
CALCULATE_HOURS_PROJECT('35:34')
                       35.566667
1 row selected.

Similar Messages

  • Expression Builder: convert string to number

    Hi all,
    I'm having trouble building a field validation rule for bank account numbers.
    The numbers have 12 positions, so I cannot use a string or text number.
    The validation rule to be implemented is that the last two digits are calculated based on the first 10 (modulo 97).
    However, when I use the Mid function to pick the first characters, I am unable to do any calculations on it. Apparently, the string to number conversion doesn't work (it should work when I read the manual, as it says that when using an operator between two data types, the second type is converted to the first (cf. example of 1234+abcd (should result in 1234 as to the manual))). So I tried '1*Mid(...)' or '0+Mid(...)'. Syntactically the expression builder accepts it and I can save it. BUT when I change the particular value on the screen, it gives me an SSO error (not the Field Validation error message I entered).
    Why isn't there simply a function ToNumber (like ToChar)????? How could I workaround this?
    Any input very welcome!
    Frederik

    Apparently, I was a bit confused when typing the first sentence, it should be:
    The numbers have 12 positions, so I cannot use an integer or number data type, but have to use String.

  • Converting string to number

    Why the number doesn't contain the whole string and how to solve it ? 
    VI is attached
    Solved!
    Go to Solution.
    Attachments:
    String to number.vi ‏7 KB

    MarinaNashaat wrote:
    binary bits
    What does that even mean?
    Post a screenshot of your VI with the data typed in.  Or put the data in the control.  Right click and save the value as defaul.  Save the VI and attach that.
    (Please put all of your information in one post.  No need to create another message.  You can even edit your previoius message within a reasonable period of time if you go to the options menu to the right of the message and choosed Edit Reply.

  • I need a java function that convert string to ASCII,

    I have a string like "test123"
    I want to convert this string to ascii code?how could I do this

    It is not compeltely clear, what you need, but String has this method:
    public byte[] getBytes(String charsetName)  throws UnsupportedEncodingException

  • Convert time to number and number to time

    I'm using SAP 4.0b
    I'm looking for function that converts time to number and number to time.
    Any suggestion?

    Hi,
    Can you give an example of what number you want to give to get what time and vice-versa?
    There can be a direct conversion between an integer and a time variable in ABAP.
    For example -
    data: number type i,
          time type syuzeit.
    number = 3600.
    move number to time.
    write time.
    The time will be output as "01:00:00". That is because 3600 seconds make up one hour.
    Regards,
    Anand Mandalika.

  • Convert String from ASCII to ANSI

    Hi,
    a command line instruction via LabVIEW function "System Exec.vi" retrieves me a string in ASCII format. Is there a function to convert string from ASCII to ANSII format? I use LabVIEW 8.5 German Installation.
    Kind Regards
    Christian
    Test Engineering
    digades GmbH
    www.digades.com

    Hallo Christian,
    AFAIK there is no such in function in LabView...
    But you can:
    - use "Search and replace string" to search for ASCII chars and replace them by their corresponding ANSI char, do this in a loop for all chars to be replaced (acceptable speed for small strings...)
    - convert the string to an U8 array and use a lookup table to convert all bytes from ASCII to ANSI, convert back to string (may be faster for long strings...)
    Best regards,
    GerdW
    CLAD, using 2009SP1 + LV2011SP1 + LV2014SP1 on WinXP+Win7+cRIO
    Kudos are welcome

  • Essbase 9.3 Calc scripts. Pb with dates. How to convert (string = number) ?

    Hello,
    I've a problem with Essbase(Planning?) Scripts on version 9.3. It looks simple but I do not find any (clean) solution :
    On my Essbase database, I have a member called "Reference_Date" on my axis Indicators. It is a date data type, that is to say, it displays a number corresponding to a YYYYMMDD format. For example : 20091029 for October 29th 2009.
    In calc scripts I often need to compare the month included in that "Reference_Date" with the current Member of my Time Axis (I have 12 Months members based on the format M02 for February for example). The final aim is to calculate a number of complete years since that "Reference_Date".
    But theses two elements are not of the same "type" (one is a number value and the other is a "member" in Time Axis). So I'm forced to convert one of this two elements in order to compare it.
    For example I can extract the month value of the "Reference_Date"' and put an "M" before it to have a Time member equivalent or I can convert the member Name M10 to a number (10))
    in both cases I have the same type problem : I don't know how to convert a string into a number nor how to convert a number into a string.
    (For example @CONCATENATE doesn't work with numbers). and that my only remaining problem.
    I didn't find any Essbase Function which do this (conversion number <=>string).
    Is anyone have an Idea ?
    Thanks for your help
    Best regards

    I don't know any way for you to compare your data against your metadata. Not directly. To me it makes little enough sense to try that I'm not surprised the developers didn't provide for it.
    I've converted member names to strings, manipulated the strings (calc script functions are not good at this), and turned them back into member names, but that's really the only use I've had for string manipulation. I don't think an equivalency operator even exists for string data. And I see no way to begin thinking of a member name, once converted to a string, as a number.
    It makes even less sense to me to try thinking of a data value as a string. Even text values in Sys 11 are stored as numbers. Not encoded characters, but just a number to look up somewhere.
    I think you can do what you want though, with something like this...
    IF (@ISMBR("FY08"))
    vYr = 2008;
    ELSEIF (@ISMBR("FY09"))
    vYr = 2009;
    ENDIF;
    IF (@ISMBR("M01"))
    vMth = 1;
    ELSEIF (@ISMBR("M02"))
    vMth = = 2;
    ENDIF;
    "Years_Since_Reference" = ((vYr * 100) + Mth) - ("Reference_Date" / 12);
    Obviously, the math will need some work, coz that doesn't actually work, but the logic above essentially turns your metadata into numbers, which is what you are after.
    Good luck,
    -- Joe

  • Not able to convert string attribute to number and date please help me out

    not able to convert string attribute to number and date attribute. While using string to date conversion it shows result as failure.As I am reading from a text file. please help me out

    Hi,
    You need to provide an example value that's failing and the date formats in the reference data you're using. It's more than likely you don't have the correct format in your ref data.
    regards,
    Nick

  • Function module to convert string to decimals?

    HI,
    is there any function module to convert string value in to decimals...string value contains exponent form...or any other way to convert if there is no funtion module..
    please let me know...
    Thanks
    Venkatesh

    Like this?
    data: str type string.
    data: f type f.
    data: p type p decimals 3.
    str = '1.2345678900000000E+08'.
    f = str.
    p = f.
    write:/ p.
    Regards,
    RIch Heilman

  • Fract String to Number converts "700,5" to 700,49999999

    I found that for some numbers the Fract String to Number vi creates a small rounding error. As an example “700,5” converts to 700,49999999. (Se attached image and vi). Is there a way to fix this?
    To see this error you have to adjust the number of digits to display in the Display format property tab. Or you can try using the round to nearest vi which will round to 700 and not 701. (This was how I found the error 
    I’m using Labview 2009.
    Terje
    Message Edited by Terje on 02-08-2010 05:00 AM
    Message Edited by Terje on 02-08-2010 05:01 AM
    Message Edited by Terje on 02-08-2010 05:06 AM
    Solved!
    Go to Solution.
    Attachments:
    rounding error.vi ‏6 KB

    Gerd,
    i just searched in the web a little bit in order to shed some light on the issue. Sadly, i found no real "solution", but something interesting:
    Due to Wikipedia (See in chapter "Character Representation"), the rounding for floating point numbers is correct with 17 decimal digits for binary64 values (which LV-doubles are).
    I previously found out, that the change from 770.5 to 700.4999 is done if the number of significant bits in the display option is set to something higher than 17 (so 18 or above).
    I find this is a fascinating coincidence......
    Norbert
    Message Edited by Norbert B on 02-08-2010 07:52 AM
    CEO: What exactly is stopping us from doing this?
    Expert: Geometry
    Marketing Manager: Just ignore it.

  • Converting strings to the floating number and plotting

    Hello,
    I have a question regardting converting string of numbers to the floating bumbers and plot for voltage vs. weight.
    The load cell for the ADC resolution is 16 bits, and the voltage will be in between +-5 volts.
    The problem, I have the most is converting the string of numbers to the floating numbers, in my case is the weight.
    Attachments:
    tunnelv1.vi ‏139 KB

    When you say "string of numbers" do you mean an array? What is the specific issue you are having? You seem to have orange wires running all over the place. Give a small example demonstrating the problem.
    Mike...
    Certified Professional Instructor
    Certified LabVIEW Architect
    LabVIEW Champion
    "... after all, He's not a tame lion..."
    Be thinking ahead and mark your dance card for NI Week 2015 now: TS 6139 - Object Oriented First Steps

  • Take the average of the measured values wich cannot be converted from string to number..

    Hello,
    I have a Keithley 182 Digital Nanometer (K182). I am usins it to measure voltage at high temperature. I want K182 to measure 3 times and then take the avarage of collected data.
    1. First problem is, as you can see from picture, string to number conversion. I tried many ways but I couldn't do it. Values as you see 0,00, and once was
    3,98E-3
    0,00
    392,0
    originan values were
    3,98E-3
    3,95E-3
    3,93E-3
    in table, values generally like this.
    2. I need to take avarege. So i need toindez data, then take avarage. So, I have also problem here...
    Could you please help on thic topic. Thanks in advance.
    Attachments:
    string-number.png ‏19 KB
    string-number-panel.png ‏30 KB

    thank you, I will try this solution. Also I want to do one more thing. So, I am collecting data and putting them in to table let say data are like this
    Temp1     Temp2   Volt
    123,3       234,5      ...
    234,4       567,7
    345,6       789,9
    456,7       678,8
    I want to put data with increment like this given below:
    No  Temp1     Temp2   Volt
    1    123,3       234,5      ...
    2    234,4       567,7    
    3    345,6       789,9
    4    456,7       678,8
    there are no exact number of data. the number of data can change from measurement to measurement (1000, 2000, 500 more or less). How can I program this increment in my system.
    My system is include LakeShore 336 temperature conroller and Keithley 182 Nanovoltmeter. I will set the temperature specified value from room temperature wtih specific ramp rate. Meanwhile I will measure the voltage from sample via K182. So, I can measure both temp, and voltage via taking help from u.

  • Converting a hex number to binary

    How do you convert a hexadecimal number to the actual 1's and 0's of binary? I am using labview 6i. Also I will eventually need the binary to be a string. Thanks.

    Converting for numeric display is quite simple. All you do is on the control/indicator, show the radix, and set it to the desired setting.
    Setting up to display the binary in text is a bit more tricky. You need to insert a "Format Value" function in and wire "%b" to the format string. This will cause the output to change to binary.
    Good luck

  • Converting String to UnitValues?

    Hello,
    how would i convert a string object to a UnitValue object?
    Say i have a an editbox.text where the user entered the string "2 in".
    How do i make it a unitvalue so i can convert it to another unit?
    regards,
    Stephan

    And here is the resulting function that parses strings as Unitvalues and does unit conversions.
    var str = Edittext.text; // user enters "10in" or "-1 pt" or anything
    var unitval = parseUnitValue(str, "mm");
    Edittext.text = unitval;
    function parseUnitValue (s, baseUnit) {
    // it's beautiful!
    // converts a string, for instance "-10.1 yard" or "0,23 mm" or ".3 pt" to a unitvalue. And then returns this value converted to baseUnit
    // for instance if s literally is "1 inch" or "1in" and baseUnit is "mm" the function will return 25.4
    // returns zero if the string doesn't parse to a unitValue!
    if (s == undefined || s == '') { s = 0 } // if string empty make Zero
    var regex = /(\-*\d*[\.|,]?\d*\s*)(in|inch|inches|ft|foot|feet|yd|yard|yards|mi|mile|miles|mm|millime ter|millimeters|cm|centimeter|centimeters|m|meter|meters|km|kilometer|kilometers|pt|point| points|pc|pica|picas|ci|cicero|ciceros)?/gi;
    var myMatch = s.match(regex);
    try {
    var stringIsValid = ( s ==myMatch[ 0 ] ); // compare the string to the regular expression matched string. If they are equal then the string fits the required form for a unitvalue.
    catch( e ) {
    var stringIsValid = false; // if the string is not valid, something in the string was bad. Perhaps it was "+-10in" or "mommy" or "10i". Its not suitable for a unitvalue.
    if (stringIsValid) {
    var sVal = s.replace(regex, RegExp.$1).split(",").join("."); // get the real value part of the string. Also convert comma to point;
    var sUnit = s.replace(regex, RegExp.$2); // get the unit part of the string.
    if (sUnit == undefined || sUnit == "") { sUnit = baseUnit; } // this is for the case when the string is a number only, like "0", or "10.2", We then assume the user wanted the baseunit.
    else { // if String doesn't parse as a unitvalue, make Zero
    alert("Unknown Unit. Try: \n in, inch, inches, ft, foot, feet, yd, yard, yards, mi, mile, miles, pt, point, points, pc, pica, picas, ci, cicero, ciceros, \n mm, millimeter, millimeters, cm, centimeter, centimeters, m, meter, meters, km, kilometer, kilometers :)");
    var sVal = 0;
    var sUnit = baseUnit;
    var myUnitValue = new UnitValue(sVal, sUnit); // create a unitvalue object...
    return myUnitValue.as(baseUnit); // ...but output its value only - converted to baseUnit

  • How to use type cast change string to number(dbl)?can it work?

    how to use type cast change string to number(dbl)?can it work?

    Do you want to Type Cast (function in the Advanced >> Data Manipulation palette) or Convert (functions in the String >> String/Number Conversion palette)?
    2 simple examples:
    "1" cast as I8 = 49 or 31 hex.
    "1" converted to decimal = 1.
    "20" cast as I16 = 12848 or 3230 hex.
    "20" converted to decimal = 20.
    Note that type casting a string to an integer results in a byte by byte conversion to the ASCII values.
    32 hex is an ASCII "2" and 30 hex is an ASCII "0" so "20" cast as I16 becomes 3230 hex.
    When type casting a string to a double, the string must conform the the IEEE 32 bit floating point representation, which is typically not easy to enter from the keyboard.
    See tha attached LabView 6.1 example.
    Attachments:
    TypeCastAndConvert.vi ‏34 KB

Maybe you are looking for

  • Pop account no longer working

    I have been downloading my gmail account to Mac Mail for 2 years now, but it is no longer working. I've gone through gmail's help page and double checked all of my settings, no issue. The error message I get: There may be a problem with the mail serv

  • IMac outputting 1080p?

    I have a 21.5 inch 2010 iMac. I have an HDMI cord connecting my iMac to my 42 inch Samsung tv. When I use the remote for my tv to change the source to HDMI2/DVI an info box says 1920x1080 @ 60hz, but the quality on the tv doesn't match the computer s

  • Safari Quicktime w any

    Almost ever time I launch Safari I get a "?" in the quicktime windows and can't view any quicktime on any site. This happens 90% of time. Sometimes everything works fine. Any thoughts. Anyone.

  • Release results to snp or r/3

    helo sir good morning how r u?? could u plz tell in which format the planning we release to SNP OR R/3??? where the unconstrained demand pland stores in SNP, in which key figure stores the demand plan in snp??? help me out sir.... thanx a lot...waiti

  • IPhoto update failed with my Panasonic GH1 raw file.

    I just installed the new package for Panasonic GH1 raw support for iPhoto 09 but it did not work. It did not recognize or allow an import of my raw file from the Panasonic.