String.toNumber()??

String S="1265";
int X=SomeMethod(S);
//X must be 1265What can I substitute SomeMethod with?

jverd wrote:
rajskhr wrote:
String S="1265";
int X=Integer.parseInt(S);this is the code might throw an exception
try itDon't you think that after reading reply 1 he could have figured that out for himself?Whaaaat?! They can think for themselves now?
@OP. No offense meant to you. It's just something that we see around these forums a lot.
Edited by: codingMonkey on 2009/10/02 10:47

Similar Messages

  • Communication between Frames

    Hi,
    I am trying to write a GUI Application,
    import javax.swing.JFrame;
    import java.awt.BorderLayout;
    import javax.swing.JPanel;
    import javax.swing.JLabel;
    import javax.swing.JMenu;
    import javax.swing.JMenuBar;
    import javax.swing.JMenuItem;
    import java.awt.*;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import javax.swing.JOptionPane;
    public class MainFrame extends JFrame
    private JLabel statusBar = new JLabel();
    private JMenuItem menuHelpAbout = new JMenuItem();
    private JMenu menuHelp = new JMenu();
    private JMenu menuPrint = new JMenu();
    private JMenuItem menuPrintNumber = new JMenuItem();
    private JMenuItem menuPrintDate = new JMenuItem();
    private JMenuItem menuFileExit = new JMenuItem();
    private JMenu menuFile = new JMenu();
    private JMenuBar menuBar = new JMenuBar();
    private JPanel panelCenter = new JPanel();
    private BorderLayout layoutMain = new BorderLayout();
    private input_invoice_no frameInvoice = new input_invoice_no();
    private input_date frameDate = new input_date();
    public MainFrame()
    try
    jbInit();
    catch(Exception e)
    e.printStackTrace();
    private void jbInit() throws Exception
    this.setJMenuBar(menuBar);
    this.getContentPane().setLayout(layoutMain);
    panelCenter.setLayout(null);
    //this.setSize(new Dimension(400, 300));
    this.setSize(Toolkit.getDefaultToolkit().getScreenSize());
    this.setTitle("Print Invoice");
    menuFile.setText("File");
    menuFileExit.setText("Exit");
    menuFileExit.addActionListener(new ActionListener()
    public void actionPerformed(ActionEvent ae)
    fileExit_ActionPerformed(ae);
    menuPrint.setText("Print");
    menuPrintDate.setText("Print Invoice By Date");
    menuPrintDate.addActionListener(new ActionListener()
    public void actionPerformed(ActionEvent ae)
    printInvoiceDate_ActionPerformed(ae);
    menuPrintNumber.setText("Print Invoice By Number");
    menuPrintNumber.addActionListener(new ActionListener()
    public void actionPerformed(ActionEvent ae)
    printInvoiceNumber_ActionPerformed(ae);
    menuHelp.setText("Help");
    menuHelpAbout.setText("About");
    menuHelpAbout.addActionListener(new ActionListener()
    public void actionPerformed(ActionEvent ae)
    helpAbout_ActionPerformed(ae);
    statusBar.setText("");
    menuFile.add(menuFileExit);
    menuBar.add(menuFile);
    menuPrint.add(menuPrintDate);
    menuPrint.add(menuPrintNumber);
    menuBar.add(menuPrint);
    menuHelp.add(menuHelpAbout);
    menuBar.add(menuHelp);
    this.getContentPane().add(statusBar, BorderLayout.SOUTH);
    this.getContentPane().add(panelCenter, BorderLayout.CENTER);
    void fileExit_ActionPerformed(ActionEvent e)
    System.exit(0);
    void helpAbout_ActionPerformed(ActionEvent e)
    JOptionPane.showMessageDialog(this, new MainFrame_AboutBoxPanel1(), "About", JOptionPane.PLAIN_MESSAGE);
    void printInvoiceNumber_ActionPerformed(ActionEvent e)
    //frameInvoice = new input_invoice_no();
    if(frameDate.isVisible())
    frameDate.setVisible(false);
    frameInvoice.show();
    void printInvoiceDate_ActionPerformed(ActionEvent e)
    //frameDate = new input_date();
    if(frameInvoice.isVisible())
    frameInvoice.setVisible(false);
    frameDate.show();
    void setInvoiceNumber(String fromNumber,String toNumber)
    statusBar.setText("From :"+fromNumber+", To Number"+toNumber);
    Upon Clicking the "Print Invoice By Number" from the Print Menu the following code is executed.
    import javax.swing.JFrame;
    import java.awt.Dimension;
    import javax.swing.JLabel;
    import java.awt.*;
    import java.awt.Font;
    import javax.swing.JComboBox;
    import javax.swing.JButton;
    import java.awt.event.ActionListener;
    import java.awt.event.ActionEvent;
    public class input_invoice_no extends JFrame
    private JLabel jLabel1 = new JLabel();
    private JLabel jLabel2 = new JLabel();
    private JComboBox jComboBox1 = new JComboBox();
    private JComboBox jComboBox2 = new JComboBox();
    private JButton jButton1 = new JButton();
    public input_invoice_no()
    try
    jbInit();
    catch(Exception e)
    e.printStackTrace();
    private void jbInit() throws Exception
    this.getContentPane().setLayout(null);
    this.setSize(new Dimension(400, 300));
    this.setTitle("Print Invoice - Select Invoice Range");
    jLabel1.setText("From :");
    jLabel1.setBounds(new Rectangle(100, 100, 40, 25));
    jLabel1.setFont(new Font("Dialog", 1, 11));
    jLabel2.setText("To :");
    jLabel2.setBounds(new Rectangle(100, 125, 35, 25));
    jLabel2.setFont(new Font("Dialog", 1, 11));
    //jComboBox1.addItem();
    jComboBox1.setBounds(new Rectangle(145, 100, 155, 20));
    jComboBox2.setBounds(new Rectangle(145, 125, 155, 20));
    jButton1.setText("Print");
    jButton1.setBounds(new Rectangle(165, 160, 65, 25));
    this.getContentPane().add(jButton1, null);
    this.getContentPane().add(jComboBox2, null);
    this.getContentPane().add(jComboBox1, null);
    this.getContentPane().add(jLabel2, null);
    this.getContentPane().add(jLabel1, null);
    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    Dimension frameSize = this.getSize();
    jButton1.addActionListener(new ActionListener()
    public void actionPerformed(ActionEvent e)
    jButton1_actionPerformed(e);
    this.setLocation((screenSize.width - frameSize.width) / 2, (screenSize.height - frameSize.height) / 2);
    private void jButton1_actionPerformed(ActionEvent e)
    My Question is how do i pass the value from the Combobox1 back to the main program.
    Thanks for your help in advance.
    Regards

    make an accessor for it.

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

  • Splitting a string into separate values, but the array length is variable

    We are a cabinet manufacturer.  I'm trying to write a report to show the location of individual hinges on a door.  I have a string that will look something like these examples:
    60, 540
    60, 540, 956
    60, 540, 956, 1340
    It may have 2, 3, 4, or 5 locations.  (Don't think I've ever seen one over 5).
    So I have a formula that says:
    Split({Doors.HingeCenterLines},',')[1]
    This will return 60 - the first figure in my string.
    I need to have all of them separated, but the critical thing is the last measurement.  I need it to be the height of the door minus the last hinge location.  So for an example, if I have a 1400mm tall door, the 4th example string listed above would be generated.  I want my entries to look like this:
    60
    540
    956
    60
    My string always references the hinge relationship to the bottom of the door, but for the top hinge only, I need it to be based on the distance from the top of the door.
    Can anyone help with this?  Thanks in advance!

    Try this code please:
    whileprintingrecords;
    local stringvar array arr := Split({Doors.HingeCenterLines},',');
    local numbervar temp;
    local stringvar fin_string;
    local numbervar i;
    For i := 1 to ubound(arr) do
         If i = ubound(arr) then
              temp := {Door_height} - tonumber(arr[i]);
              fin_string := fin_string + totext(temp,0,"");
         else
              fin_string := fin_string + arr[i] + chr(13);
    fin_string;
    You can then right-click the field > Format Field > Common tab > Check the 'Can Grow' option.
    -Abhilash

  • Crystal report static string parameter is running with null value too...

    Hi All,
    I am new to crystal report . I am using crystal report XI and in the report I designed contain one static string parameter. If I not enter any value in that parameter field still myu report get run.As per requirement I dnt want to run report unless user enter any value in that field. How to do it? Please help. any comment is valuable.
    Thanks

    Thanks Json ..
    your solution really helps me.Thanks again.
    One more issue is here,
    I have one subreport . In that  'amount ' field is present which have data type as 'character'  in database. I convert it in numeric by using following fromula,
    if NumericText ({Command.AMOUNT})
    then                                                     
    ToNumber ({Command.AMOUNT})
    when I run report in designer, it works but when I run it on crystal report server it throws error ad "Error in File :Error in formula . 'if NumericText ({Command.AMOUNT}) ' This field name is not known. Details: errorKind "
    Can u please help me out of it.
    Edited by: girish_613 on May 10, 2010 10:25 AM

  • [CR integrated in VS 2005] - sum of string fields

    Hello,
    i am discovering CR,
    and i am trying to do the sum of a field (number) but declared as string. the declaration of the field cannot be changed (string in the database).
    so i want to do the sum of this field.
    i wonder if it is possible, and if yes, how.
    maybe something like a formula.
    I saw the functions: ToNumber () and Cdbl() for conversion, and Sum().
    If someone has an idea, i will be very interested.
    PS: sorry if my question is not understandable, i'm french. If you don't understand it, i would rewrite it.
    thank you!

    thank you.
    I could convert, but the problem is to make the sum of the conversion.
    i would like to do something like:
    Sum(ToNumber ()) but CR does not accept it.
    Maybe by using a variable in a formula (but i don't know where):
    shared numbervar total;
    total = total+ToNumber({MyField});
    and when printing a formula field at the bottom of the report to show the total:
    shared numbervar total;
    ToText (total);

  • Convert string (in a Julian Date format) to a date in CR XI Release 2

    How do you convert a string field  entered in a database as a Julian date " 10109 , 09008. ,,," to
    print on a report as  date?
    09008 would be 01/08/09
    10109                 04/19/10

    A small correction to Brian's formula:
    NumberVar myYear;
    NumberVar myDays;
    myYear := ToNumber( {table.JULIAN} [1 to 2]);
    myDays := TONUMBER({table.JULIAN} [3 to 5]);
    (Date (myYear, 1, 1) + myDays) - 1;
    The result for '09008' will be 01/08/9, by adding ToText, you can get the result in the desired format of 01/08/09.
    totext((Date (myYear, 1, 1) + myDays) - 1, "MM/dd/yy");
    Here is an alternate solution without having to create variables:
    totext(dateserial(tonumber(X[1 to 2]),1,tonumber(X[3 to 5])),"MM/dd/yy");
    where X is the julian date in string.
    Edited by: Sanjay Kodidine on Apr 20, 2010 8:25 AM

  • Convert HH:mm:ss String format.

    Hi,
    I have a formula in webI to display Milliseconds to HH:mm:ss and is in String format.
    Is there a way to convert to date or number format?.
    Also, how to calculate average of Max and Min time?.
    Thanks,
    Jothi

    Hi Jyothi,
    To take a average time do following-
    1) Convert Min Time and Max Time into Seconds.
    MaxSec=ToNumber(Substr([MaxTime];1;2))*60*60+ToNumber(Substr([MaxTime];4;2))*60+ToNumber(Substr([MaxTime];7;2))
    MinSec=ToNumber(Substr([MinTime];1;2))*60*60+ToNumber(Substr([MinTime];4;2))*60+ToNumber(Substr([MinTime];7;2))
    2) calculate approximate Avg seconds-
    AvgSec=([MaxSec]+[MinSec])/2
    3) Convert AvgSec in to hh:mm:ss.
    AvgTime=Floor([AvgSec]/3600 )+":"+Floor(Mod([AvgSec];3600)/60)+":"+Mod(Mod([AvgSec];3600);60)
    Hope this help.
    Thanks,
    Anuj

  • How to get how many lines a formatted string has

    ih, is there a way to get by formula code the object's number of lines once it has been formatted by the format editor checking the the Can Grow check with 0 as maximum number of lines?
    The Can Grow check can offer you to enter the Maximum number of lines the object can grow...so...the object's number of lines somewhere is stored in order to confront it with the number one has entered in Maximum number of lines' input box.
    thank you in advance

    Hello,
    No or maybe, the problem is is when you select 0 it's unlimited, CR simply fills the first line and continues on until no more test to display. Then it determines how much space is left over for the rest of the report sections and so on...
    Possibly you could use the String Length function and divide by the page width:
    numbervar mynumbervar;
    mynumbervar :=  2 / tonumber(Length ({Command2.ROW_UNIT_NAME}));
    2 is the width of the field object in inches and then you also have to determine how many characters per inch the font is going to use.
    There are 1440 twips per inch and if your font is set to 10 then it's something like 1440/10 ( although you need to determine how many characters per inch the font really uses. This can vary depending on the font, most are not fixed width so it's only an estimate..
    Anyways, why do you need to know? CR will simply set the space required?
    Or are you wanting to have the same space all the time and try to determine what that is? If so then you'll also have to set it globally because the format will be evaluated for each time it prints.
    Don

  • Converting scientific notation string to number?

    This is raising an error:
    > ToNumber (u201C2.75E-05u201D)
    How do you convert scientific notation strings to numbers?
    This is coming from XML. I can probably have the XML written so that it's not scientific notation.
    Tim

    Here's a not-so-pretty way:
    Local StringVar Array x;
    Local StringVar mantissa;
    Local StringVar exponent := "0";
    // Split into mantissa and exponent parts.
    x:= Split("24.2233E+2", "e", 2, 1);
    mantissa := x[1];
    If (UBound(x) = 2)
    Then
        exponent := x[2];
    // CDbl cannot interpret leading positive sign, so removie
    If Left(mantissa, 1) = "+"
    Then
        mantissa := Right(mantissa, Length(mantissa) - 1);
    If Left(exponent, 1) = "+"
    Then
        exponent := Right(exponent, Length(exponent) - 1);
    // Compute number
    CDbl(mantissa) * 10 ^ CDbl(exponent);
    Sincerely,
    Ted Ueda

  • String to number and Number to String Problem!

    Hi All,
    In my report i ahve to display the Date.
    From DB i am getting 4 digit string( 2008). Using that i have to display as 08 - 09
    In that i used RIGHT function. it is diplayed as 08 - 9.
    when i take 2 character from right '08' is coming. Then i converted to number and added 1 to the year
    But it become 9 instead of 09.
    How to solve it.
    Thanks in advance.
    Saravanakumar.

    Hi,
    Shweta's answer is valid when you retrieve a date field from the database, as you have specified that you are getting a four digit string, you should use this formula.
    if length(totext(tonumber(right('2008',2))+1)) = 4
    then
    right('2008',2)'-0'left(totext(tonumber(right('2008',2))+1),1)
    else
    right('2008',2)'-'left(totext(tonumber(right('2008',2))+1),2)
    hope this helps!!!
    Thanks
    -Azhar
    Edited by: Abdul Rehman Mushtaque on Mar 29, 2009 10:29 AM

  • How do I format a date string in ISO 8601 format?

    Post Author: Perth
    CA Forum: Formula
    I am using a SaaS application, and uploading Crystal XI report templates to run using the application's reporting page. My custom date fields are stored using the ISO date format, and are made available as text strings in the form "yyyy-mm-ddThh:mm:ss" eg. "2007-10-09T00:00:00". The SaaS vendor say use a Crystal function. I have tried CDATE, DATEVALUE etc but these don't recognise the format as a valid date. I want to display this date as dd mmm yyyy.  Any ideas?

    Post Author: Perth
    CA Forum: Formula
    I have found a solution from another forum and post it here to close this off.
    It requires defining a "Report custom function". Use the formula workshop to create a function, giving it a name. Then paste this:
    Function  (stringVar v1)Date (ToNumber (Left (v1,4 )),      ToNumber (Mid (v1, 6,2 )) ,      ToNumber (Mid (v1, 9,2 )) )
    I can now format this date in the normal way as it is a date!

  • Formula for getting first letter of the string

    Post Author: jmmj
    CA Forum: Formula
    Hi, I have a problem to get the first letter of the string.  I need to compare first letter first and then change the rest of string to number as unit cost for calculation.  For example, I have string K100, C200,...     if first letter = K then 0 else if first letter = C then tonumber200..... I use CRXI, any assistance will be appreciate.jmmj 

    Post Author: jmmj
    CA Forum: Formula
    It works, thanks Kai!But when I tried to print the report, there are multiple lines shown same invoice number but different unit price. My formular is: IF {OEINPR3.COINTYPE} = 2 OR CCur({OEINPR3.LINETYPE}) = 1  //line type 1 for item,  2 for misc. charge THEN(    IF {OEINPR3.COIN}[1] = "K" OR {OEINPR3.COIN}[1] = "N"  THEN        TONUMBER(MID({OEINPR3.COIN},2,20))    ELSE 0)ELSE      2 //for testing only The result I have: Line#    Inv#    unitprice    total1          IN001    0.00     10.00            IN001   10.00     10.00  2          IN002    0.00     20.00             IN002    20.00     20.00.......The second line of each invoice is correct. How can I print just one line for each invoice which is correct? Thanks!jmmj  

  • Issue converting with function ToNumber

    Hi
       I have in one infocube a ratio with datatype Quantity [QUAN] and it's an attribute from a Z infoobject when i create the universe was datatype char and it's qualification = detail.
      When i list in a webi reports appears like 0.125L, 0.175L because the unit of measure is Liters i create a variable with the following formula  =ToNumber(Replace([Factor Convertir Litros];"L";""))
    And shows in the cell #ERROR
    When i try only =Replace([Factor Convertir Litros];"L";"") appears 01.25 and 0.175 but the ToNumber not works and i need this variable with datatype number in order to do some calculations.
    In Bex Analyzer exists the function NODIM to eliminate the unit of measure, also i try to create in the universe as datatype number but also i get errors.
    Somebody can help me please
    Regards Marvin

    Hi Marvin,
    Try to convert it as:
    ToNumber(Substr([Quan];1;Pos([Quan];"L")-1))
    Assuming Quan to be of String data type
    Regards,
    Rohit

  • Doing mathematical formulas with numbers stored as strings

    Hi Everybody.
    I know I must be doing something stupid here, but I just can't see it.
    I'm just trying to do a simple maths formula of one number divide by another. However, one of the numbers is stored as a string.
    I have tried  'X' / Ccur ({'String'}) and even done a seperate formula that succesfully converts the string to a number and  then try 'X' /  ({'conversion formula'}) and still no luck.
    What am I missing and can anybody help please?
    Thanks
    Graham

    Thanks both.
    Works perfectly. Didn't see the ToNumber conversion in the choices available and have not used it before.
    I'll also provide better descriptions as well in the future.
    Regards
    Graham
    Points awarded accordingley  :O)

Maybe you are looking for