Strings to Numbers

I'm trying to create a simple batting average calculator that
displays an average in a dynamic text box assigned to the variable
"avg" everytime the "button" instance is pressed down. No matter
how many times I try this, I get "NaN" to show up as the "avg"
value. What am I doing wrong?

Are hits and ab have numerical values? In your onPress
handler, try:
trace(hits);
trace(ab);
trace(Number(hits));
trace(Number(ab));

Similar Messages

  • Starting a string of numbers with zero

    This may be a really dumb question, and I apologize if it is, but how do I start a string of numbers in a cell with zero. Each time I try the zero is deleted automatically when I go to the next cell. Thanks for any tips.

    If you set the format of the cell to "Text", this will let you enter a string like:
    01234
    No additional effort is required (like ="01234")
    And, if your intent is that this is really a numeric quantity rather than a string composed of digits, Numbers will let you refer to this cell as if it were a number. For instance if this number in A1, then in B1 you enter =A1+1, the result will be the number quantity 124.

  • I would like to read a file and display the results in a table containing both strings and numbers?

    Hi,
    I just need a simple way of doing this as at the moment, i read one line at the time containing strings and numbers, whenever i convert this line to an array i loose the strings, if i want to display it, it displays as a group of lines while i would like to display it as a table with column headers. The file is an .xls worksheet.
    Any suggestions?
    Thanks
    Me

    Hi,
    Look at attach vi.
    If this is not what you need please clarify.
    With ActiveX you can Open Excel, interact with it (read and write values to cells...
    But if you can read it this way, I think it's easier.
    Hope this helps,
    Paulo
    Attachments:
    XL.zip ‏24 KB

  • Converting a string of numbers into an array of booleans

    For a homework assignment, I need to convert a string of numbers into an array of booleans.  The string is a bunch of random numbers (0-9) in sequence, with no spaces.  It looks something like this: 0123452348949230740329817438120947392147809231419.  I need to make it so that each even number represents a "True" boolean and so that each odd number represents a "False" boolean.  I think that I first need to convert each element of the string into a number, and then use a case structure (or something) to say, for each element of the array, "If even, then true.  If odd, then false," but I could be wrong.  Any suggestions?

    billko wrote:
    Hooovahh wrote:
    billko wrote:
    Sounds reasonable.  Think about the definition of "odd" and "even" and it will make life a lot easier. 
    I know you are trying to be vague but I'd like to give a key hint.  Use the Quotient and Remainder function.
    LOL maybe that was one of the objectives of the homework. 
    To be fair it sounds like there is more work that is needed.  A new user of LabVIEW will have a hard time figuring out how to process each character one at a time when it isn't in an array.  
    It's just that most people (me at least) stopped thinking about division with quotient and remainder after basic algebra.  I then of course changed my way of thinking when I used LabVIEW.  Still most of the time when you use division you want to know the fractional part as a decimal.  Thinking this way makes the problem more difficult then it needs to be.
    Unofficial Forum Rules and Guidelines - Hooovahh - LabVIEW Overlord
    If 10 out of 10 experts in any field say something is bad, you should probably take their opinion seriously.

  • Help Sorting array of strings with numbers in them

    Hello I need to sort an array of Strings of numbers. The order is not what I want it to be. instead of 1, 5, 20 it will go 1, 20, 5.
    I did a google search for this and found some code that could fix this. The only problem is I tried using it as a method in my program and am getting a compile-time error that I'm not sure how to fix.
    C:\Documents and Settings\Owner\Desktop\stringcompare.java:18: '(' or '[' expected
                new Comparator<String>()
                                    ^I'm not sure what to do here. Any help would appreciated.

    import java.io.*;
    class MyProgram{
    //This is my old bubble sort method which screws up with numbers
    public static String[] sort( String[] points)
              boolean keepGoing = true;
              while(keepGoing == true){
                   keepGoing = false;
                   for(int i = 0; i < points.length - 1; i ++)
                        if(points.compareToIgnoreCase(points[i + 1]) < 0)
                             String temp = points[i];
                             points[i] = points[i + 1];
                             points[i + 1] = temp;
                             keepGoing = true;
              return points;
    //This method reads a pre-existing text file
    public static String[] readPoints() throws IOException
              FileReader file = new FileReader("points.txt");     
              BufferedReader in = new BufferedReader(file);
              String temp;                
              String[] list = new String[100];     
              int i = 0;
              while (i < list.length)                    
                   temp = in.readLine();
                   if (temp != null)
                        list[i] = temp;                    
                   else
                        list[i] = " ";
                   i++;
              in.close();                              
              return list;
    //rewrites file after being sorted
         public static void savePoints(String[] points) throws IOException
              FileWriter file = new FileWriter("points.txt");
              BufferedWriter out = new BufferedWriter(file);
              int i = 0;
              while (i < points.length)          // while the end of file is not reached
                   out.write(points[i]) ;
                   out.newLine();
                   i++;
              out.flush();
              out.close();
    public static void main(String[]args) throws Exception{
    String[]points = new String [100];
    points = readPoints();
    points = sort(points);
    savePoints(points);
    for(int i = 0; i < points.length - 1; i++)
    System.out.println(points[i]);
    The problem is that it doesn't sort as I would like it and I'm not sure how to get the comparator to work properly.
    Edited by: myol on May 31, 2008 4:21 PM
    Edited by: myol on May 31, 2008 4:23 PM                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • How do I insert a WAIT or a PAUSE function, followed by a constant string of numbers [international code, country code and the destination phone number].

    I'd like to program a LOCAL ACCESS NUMBER, then insert a WAIT or a PAUSE function, followed by a constant string of numbers [international code, country code and the destination phone number]. Dialing the local, US  access number is not an issue, but I can't find any info in the manual on how to insert a WAIT or PAUSE or how to insert the remaining string of international codes and destination phone number. Any help would be appreciated. Thanks!

    How to Add Pauses when you Dial a Number on the Samsung Galaxy Note 3 - For Dummies
    It is also described on page 42 of your owners manual...

  • Find & replace part of a string in Numbers using do shell script in AppleScript

    Hello,
    I would like to set a search-pattern with a wildcard in Applescript to find - for example - the pattern 'Table 1::$*$4' for use in a 'Search & Replace script'
    The dollar signs '$' seem to be a bit of problem (refers to fixed values in Numbers & to variables in Shell ...)
    Could anyone hand me a solution to this problem?
    The end-goal - for now - would be to change the reference to a row-number in a lot of cells (number '4' in the pattern above should finally be replaced by 5, 6, 7, ...)
    Thx.

    Hi,
    Here's how to do that:
    try
        tell application "Numbers" to tell front document to tell active sheet
            tell (first table whose selection range's class is range)
                set sr to selection range
                set f to text returned of (display dialog "Find this in selected cells in Numbers " default answer "" with title "Find-Replace Step 1" buttons {"Cancel", "Next"})
                if f = "" then return
                set r to text returned of (display dialog "Replace '" & f & "' with " default answer f with title "Find-Replace Step 2")
                set {f, r} to my escapeForSED(f, r) -- escape some chars, create back reference for sed
                set tc to count cells of sr
                tell sr to repeat with i from 1 to tc
                    tell (cell i) to try
                        set oVal to formula
                        if oVal is not missing value then set value to (my find_replace(oVal, f, r))
                    end try
                end repeat
            end tell
        end tell
    on error number n
        if n = -128 then return
        display dialog "Did you select cells?" buttons {"cancel"} with title "Oops!"
    end try
    on find_replace(t, f, r)
        do shell script "/usr/bin/sed 's~" & f & "~" & r & "~g' <<< " & (quoted form of t)
    end find_replace
    on escapeForSED(f, r)
        set tid to text item delimiters
        set text item delimiters to "*" -- the wildcard 
        set tc1 to count (text items of f)
        set tc2 to count (text items of r)
        set text item delimiters to tid
        if (tc1 - tc2) < 0 then
            display alert "The number of wildcard in the replacement string must be equal or less than the number of wildcard in the search string."
            error -128
        end if
        -- escape search string, and create back reference for each wildcard (the wildcard is a dot in sed) --> \\(.\\)
        set f to do shell script "/usr/bin/sed -e 's/[]~$.^|[]/\\\\&/g;s/\\*/\\\\(.\\\\)/g' <<<" & quoted form of f
        -- escape the replacement string, Perl replace wildcard by two backslash and an incremented integer, to get  the back reference --> \\1 \\2
        return {f, (do shell script "/usr/bin/sed -e 's/[]~$.^|[]/\\\\&/g' | /usr/bin/perl -pe '$n=1;s/\\*/\"\\\\\" . $n++/ge'<<<" & (quoted form of r))}
    end escapeForSED
    For what you want to do, you must have the wildcard in the same position in both string. --> find "Table 1::$*$3", replace "Table 1::$*$4"
    Important, you can use no wildcard in both (the search string and the replacement string) or you can use any wildcard in the search string with no wildcard in the replacement string).
    But, the number of wildcard in the replacement string must be equal or less than the number of wildcard in the search string.

  • Is there a way to type cast an array of strings to numbers and back again?

    I'm working on an application where I want to type cast a string like "power supply" into an array of existing numbers. Then sort the existing numbers, and finally convert the casted numbers back into a string so it can be read by the user. In the attachment, you can see my latest attempt with flatten/unflatten data and the 'convert string to byte array'. I can't seem to make this work. Any ideas?
    Thanks - Paul
    Attachments:
    Paul's Temp scan for components.vi ‏56 KB

    OK, here's a quickie (LabVIEW 7.0).
    Simply get the sort key from the 1D array, then build the table.
    Message Edited by altenbach on 10-27-2006 01:34 PM
    LabVIEW Champion . Do more with less code and in less time .
    Attachments:
    SortedTable.png ‏4 KB
    SortedTable.vi ‏37 KB

  • Can't convert my String to numbers

    Hi!
    I'm trying to convert my received data to numbers in actionscript in Flex.
    I want to use the numbers that I get in a calculation.
    The function where the data ("Svar") in received and saved in a string looks like this:
    Svar.htmlText = event.result.toString();
    And this is the calculation that I want to do:
    var r:Number = Number(Svar)/2.1;
    var newheight:Number = 420 * r;
    var newwidth:Number = 162 * r;
    resizeLarge.widthTo = newwidth;
    resizeLarge.heightTo = newheight;
    resizeLarge.duration=750;
    I've checked the calculation and it works so it must be something wrong with the
    "Svar" data.
    I'd be really grateful if someone could help me!

    Hi,
    You are doing something wrong with the calculation in the below line of code.
    var r:Number = Number(Svar)/2.1;
    Here what does Svar corresponds to....Is it a variable or a Labeel control....?
    I think Svar is some kind of a Label or Text control since in your code you have used "htmlText: attribute with the "Svar" as shown below.
    Svar.htmlText = event.result.toString();
    So in your calculation also you need to use the same ...I mean ...text property as shown below..
    var r:Number = Number(Svar.text)/2.1;
    Dont use Svar.htmlText  in calculation as it may give include unnecessary htmltags and your conversion from string to Number fails.
    Hope now the things are clear...If you still have any dobt let me know.
    If this post answers your question or helps, please kindly mark it as such.
    Thanks,
    Bhasker Chari

  • In LabVIEW, how to put a string of numbers stored in the array?

    That is the question.Please.

    What is the data format.  Comma delimited string of ASCII numbers?  Please provide an example to clearly show what you currently have and what it is that you want.
    There are only two ways to tell somebody thanks: Kudos and Marked Solutions
    Unofficial Forum Rules and Guidelines

  • How to create a string with numbers, separated by ",".

    Hello!
    I have a start number and a end number. For example 101 and 110.
    Now I want to create a string containing all numbers between 101 and 110 separated by comma(",").
    (101,102,103 .......,110)
    Any smart suggestions?

    Hello EKrille,
    I changed the vi from tst to give the same results on both options...
    Best regards,
    GerdW
    Best regards,
    GerdW
    CLAD, using 2009SP1 + LV2011SP1 + LV2014SP1 on WinXP+Win7+cRIO
    Kudos are welcome
    Attachments:
    string.vi ‏26 KB

  • Troubles writing a string of numbers in binary mode to a file.

    Hi,
    I have a string stringRW = "1234567890". I want to write this numbers to a binary file. For that, I am doing this:
    fileDestiny = new File(arquivo);
    o = new FileOutputStream(fileDestiny);
    out = new BufferedOutputStream(o);
            int i = 0;
            int x;
            while ((x = stringRW.codePointAt(i)) != -1) {
                try {
                    out.write(x); // Copia o arquivo.
                    System.out.println("byte = "  +x);+
    +            } catch (IOException ex) {+
    +                Logger.getLogger(ArquivoEscreverBin.class.getName()).log(Level.SEVERE, null, ex);+
    +            }+
    +            i++;
    out.close();Actualy, I am getting some Exception:
    Exception in thread "Thread-3" java.lang.StringIndexOutOfBoundsException: String index out of range: 11
            at java.lang.String.codePointAt(String.java:715)
            at jserialrwxn.ArquivoEscreverBin.write(ArquivoEscreverBin.java:46)
            at jserialrwxn.NewSerialX.setDados(NewSerialX.java:890)
            at jserialrwxn.SerialComRW.serialEvent(SerialComRW.java:276)
            at gnu.io.RXTXPort.sendEvent(RXTXPort.java:732)
            at gnu.io.RXTXPort.eventLoop(Native Method)
            at gnu.io.RXTXPort$MonitorThread.run(RXTXPort.java:1575)But the problem in fact, is that the generated file is not a binary file. For check if the generated file is or not binary, I do open it in Notepad. When I do open the generated file with Notepad I can read it normaly and see the numbers 1234567890.
    Some one have some guess on how I need to proceed?
    Edited by: cstrieder on Aug 5, 2009 1:15 PM

    cstrieder wrote:
    Hi,
    I have a string stringRW = "1234567890". I want to write this numbers to a binary file. For that, I am doing this:Are you saying that you want to write the individual characters of your string to a file? Or are you saying that you want to write the integer values from your string to a file? I.e., do you want to write the number "1" as a character or do you want to write the value 1 to a file?
    >
    fileDestiny = new File(arquivo);
    o = new FileOutputStream(fileDestiny);
    out = new BufferedOutputStream(o);
            int i = 0;
    int x;
    while ((x = stringRW.codePointAt(i)) != -1) {
    try {
    out.write(x); // Copia o arquivo.
    System.out.println("byte = "  +x);+
    +            } catch (IOException ex) {+
    +                Logger.getLogger(ArquivoEscreverBin.class.getName()).log(Level.SEVERE, null, ex);+
    +            }+
    +            i++;
    out.close();Actualy, I am getting some Exception:
    Exception in thread "Thread-3" java.lang.StringIndexOutOfBoundsException: String index out of range: 11
    at java.lang.String.codePointAt(String.java:715)
    at jserialrwxn.ArquivoEscreverBin.write(ArquivoEscreverBin.java:46)
    at jserialrwxn.NewSerialX.setDados(NewSerialX.java:890)
    at jserialrwxn.SerialComRW.serialEvent(SerialComRW.java:276)
    at gnu.io.RXTXPort.sendEvent(RXTXPort.java:732)
    at gnu.io.RXTXPort.eventLoop(Native Method)
    at gnu.io.RXTXPort$MonitorThread.run(RXTXPort.java:1575)
    Your exception is telling you exactly what the problem is. Your index is beyond the length of your string. Instead of using a while loop to iterate over the String, try using a for-loop instead. i.e.
    for(int i = 0; i < myString.length(); i++) {
      // blah blah blah
    But the problem in fact, is that the generated file is not a binary file.Every file is a binary file. What you're doing is writing the character value to the file. Instead of that, you may want to try parsing your character value into an integer and then writing that value.
    For check if the generated file is or not binary, I do open it in Notepad.That's not an appropriate method for determining the byte values written to your file(s). Use a hex editor instead.
    When I do open the generated file with Notepad I can read it normaly and see the numbers 1234567890.Again, that's because you're writing the character values, not the integer values.

  • Storing strings and numbers in a spreadsheet

    in this file i understand that the data types are incorrect. but what i dont know is how to fix it so i can write arrays filled with strings and arrays filled with numbers to seperate columns in an excel spreadsheet.
    Solved!
    Go to Solution.

    sorty here it is.  thanks.
    Attachments:
    learning with kevin 17.vi ‏119 KB

  • Table Sorter for String displaying Numbers

    Hi All.
    I have a table whose one of the columns display numbers with data type string. This is becuase :
    1. RFC gives me as String.
    2. I have to display blank in case no value or zero is present (since int, long etc default to Zero, hence  
        not used).
    I have to sort this column as a number.Since the datatype is string, it sorts the numbers as string
    for example : if we have  values like : 2, 4, 3, 10, 19, 15, 20, 22
    currently as String it sorts as follows : 10, 15, 19, 2, 20, 22, 3, 4.
    but i want as follows : 2, 3, 4, 10, 15, 19, 20, 22.
    Useful answers will appreciated.
    Thanks and regards,
    Aditya Deshpande.

    In order to sort the node with attribute of type string; please use the following code..
    Here use the node where you store the string value..
    wdContext.nodeTest().sortElements(
                new Comparator() {
                   public int compare(Object o1, Object o2) {
                        // TODO Auto-generated method stub
                   IPrivateExperimentView.ITestElement ele1 = (IPrivateExperimentView.ITestElement)o1;
                   IPrivateExperimentView.ITestElement ele2 = (IPrivateExperimentView.ITestElement)o2;
                        return Integer.parseInt( ele1.getNumStr()) > Integer.parseInt( ele2.getNumStr()) ? 1 : -1;
    input :  "2", "4", "3", "10", "19", "15", "20", "22"
    result : "2", "3", "4", "10", "15", "19", "20", "22"
    vinod

  • InDesign CS4: File names change to string of numbers

    Occasionally, one of our users will save an InDesign CS4 file, only to have the file name change.  For example, a file originally named "#kwn25501.bcbsNM.indd" was saved as "#kwn25501.bc157-1223857848."
    If the user is not aware that this has happened, things can go horribly, terribly wrong in our production environment. The "numbered" file may be missing key elements, or be somehow be corrupt in some fashion. In one case, this led us to having to reprint a job because the "numbered" file was missing a photo; somehow, that file was used (and perhaps renamed after the fact) to create the final output.
    We use Macs running InDesign CS4 6.0.5. Some of our Macs are running Tiger 10.4.11, while others are running Leopard 10.5.8. The problem seems to related to the Leopard machines, although that is not 100 percent certain at this point. All of these Macs are bound to Active Directory and save files to a Windows 2003 server. I know Adobe recommends against working on files over a network, but perhaps there is an explanation for this file renaming aside from network issues.
    Any light that can be shed on this issue will be greatly appreciated. Thanks!
    Kevin Stauffer

    Check to see if maybe your original filename is the problem.
    You may need that particular name for a workflow reason, but some of the symbols in the middle of your filename are generally not a good idea. Especially working off of a server, file names should be ONLY alpha-numeric characters, no symbols, no periods (except for the file type) and only underscores or dashes to separate words, no spaces.
    The reason is some of those symbols get picked up as machine language and all sorts of bad can happen as a result.
    Message was edited by: Michael Riordan

  • Converting strings to numbers

    import java.io.*;
    import java.util.*;
    class D{
         public static void main(String[] args)throws IOException{
         Scanner in = new Scanner (System.in);
         //51 3 15 * - 9 65 13 / - + example of expression to enter
         System.out.print("Enter PostFixExpression :");
         String s = in.next();//I am aware that I cannot read them as characters so I am using string
        while(!s.equals("")){
             if(String.isDigit(s)){//line 13
                  System.out.printf("%d",s);
             }else{
                  System.out.println("I am not a digit ");
             s = in.next();
         }//main
    }//classerror: cannot find symbol method isDigit(java.lang.String) line 13
    when I use Character.isDigit(s), it separates the digits, for example 51 becomes a 5 and a 1. How can I manipulate the data so that the digits in the number stays together?
    --------------------------------------------------------------------------------

    chetah wrote:
    error: cannot find symbol method isDigit(java.lang.String) line 13Right. As the error message tells you, String does not have a static isDigit method that takes a String arg.
    when I use Character.isDigit(s), it separates the digits, for example 51 becomes a 5 and a 1. No, that's not what isDigit does. It simply tells you whether a given character is a digit or not. You have to separate them yourself first.
    How can I manipulate the data so that the digits in the number stays together?Well, if you want to examine the individual characters to test whether they're digits, you'll have to break the String into chars. So look at String's methods to see if you can find one that will help you with that. Note that Strings are immutable, so you already know that your original String will remain untouched.

Maybe you are looking for