Converting string number int o percentage

Hi. I have a textfield in which it accepts numbers (2.5 or 2.35 or 32.52)
How am I going to convert it to double and in percentage format( .0025 or .0035 or .003252)
Thanks
Please help

> and just converting it back to string again. I made
the division but converting it back to string.
what function do i need to use?
In Java they're called "methods".
http://java.sun.com/developer/JDCTechTips/2004/tt1005.html#2
http://java.sun.com/docs/books/tutorial/i18n/format/decimalFormat.html
~

Similar Messages

  • How to convert String to int in JSP?

    Hi,
    I set a session attribute in Servlet and want use it in JSP, How can I convert it to int or Integer?
    the line in my code doesn't work:
    int quantity=(int)session.getAttribute("vehiclequantity") ;
    Thanks in advance.
    Wolf
    +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    <HTML>
    <HEAD>
    <TITLE>Using the for Statement</TITLE>
    </HEAD>
    <BODY>
    <H1>Using the for Statement</H1>
    <%=session.getAttribute("vehiclequantity") %>;
    <%
    int loopIndex;
    int quantity=(int)session.getAttribute("vehiclequantity") ;
    out.println(quantity);
    for (loopIndex = 1; loopIndex <=2; loopIndex++) {
    out.println("This is iteration number "
    + loopIndex + "<BR>");
    %>
    </BODY>
    </HTML>

    Learning how to read errors and understand them will help you solve your problems quicker by yourself... So lets take a look at the error and classes involved...
    The error says:
    "Cannor Resolve Symbol: method valueOf(java.lang.Object) in the class java.lang.Integer" and gives you line line where the error occurs: Integer quantity = Integer.valueOf(session.getAttribute("vehiclequantity"));
    Now, if we look at the API for the Integer we notice that are are only two valueOf methods: valueOf(java.lang.String s) and valueOf(java.lang.String s, int radix). Not valueOf(java.lang.Object) method.
    Now we look at the getAttribute(java.lang.String name) method of HttpSession we see that the method returns a java.lang.Object. Now, you know you put a java.lang.String into that attribute, but the get method returns an Object. This is because you could have put any object in there, an Integer, a String, or some other class instance. But you know it is a String, so you can cast the returned value to a String, so that you will be calling the valueOf(java.lang.String s) method of Integer with the Object returned from the HtttpSession's getAttribute(java.lang.String name) method:
    Integer quantity = Integer.valueOf((String)session.getAttribute("vehiclequantity"));

  • 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

  • Converting string to int

    I cannot convert this string to integer.
    int tempI = Integer.parseInt("fdcedfbd", 16);
    it returns a numberFormatException
    but if I do this then there will be no problem.
    int tempI = 0xfdcedfbd
    Can anybody help me with this? Thank you.

    It sounds like the real problem here is that someone is giving you an 8-byte unsigned value represented as a 16-character hexadecimal string, and they want you to convert that into the actual 8 bytes. Are they going to do bit manipulation on it or something?
    If you successfully convert it into a long and they then try to do math with it, they'll run into the sign/overflow problems everyone else has been talking about. If they just want to look at the individual bits then it would make sense to do the conversion into a long.
    You could do something like this:
      private static final String highOrderDigits = "89abcdef";
      public long hexToLong(String hex) {
        // Only process exactly 16-digit strings.
        if (hex.length() != 16) {
          throw new IllegalArgumentException("Expect 16-digit hex value");
        boolean overflow = false;
        // Check for most significant digit > 7, which would
        // cause problem for parseLong.
        int highOrderIndex = highOrderDigits.indexOf(hex.charAt(0));
        if (highOrderIndex > -1) {
          // Clear most-significant bit and set overflow flag.
          overflow = true;
          hex = "" + highOrderIndex + hex.substring(1);
        long result = Long.parseLong(hex, 16);
        if (overflow) {
          // Manually set most significant bit in result.
          result |= 0x8000000000000000L;
        return result;
      }I more or less tested this and it looks to work.

  • Exception thrown trying to convert string to int

    Hey Guys,
    i imported a csv file into my app which i divide using the split() method and put into an array then I divided the array into variables;
    fruit = piece[0];
    price = piece[1];
    unit = piece[2];Now since price has to be a double i converted it into a double;
    price2 = Double.parseDouble(price);which worked grand
    but when i try to convert unit to an integer
    unit2 = Integer.parseInt(unit);i got error
    Exception in thread "main" java.lang.NumberFormatException: For input string: "3
    at java.lang.NumberFormatException.forInputString(Unknown Source)
    at java.lang.Integer.parseInt(Unknown Source)
    so i tried removing white spaces as follows
    target = unit.replace(" ", "");which worked and displayed grand, then i tried converting to int again but the same exception was thrown, can anyone help me with this problem, thanks
    mark

    sorry for the messed up format previously.
    Like you said the unit.replaceAll(" ", ""); did not do the trick, when displayed as a string it looked like 3 was on its own but still did not convert to int. I assume line break or something existed in the csv file like you mentioned earlier as unit was the last word in the csv file.
    when i used unit.trim(); and tried to convert to integer it worked perfectly.
    thanks all for your help,
    Mark

  • Problem converting string to int

    I want to display records of flights from my database with the things that i get from a form...One of them is the number of passengers...the code is shown below;
    " SELECT * FROM flights WHERE kalkis LIKE ? AND inis LIKE ? AND DepartureDate LIKE ? AND NumPass >= ? ";
    Everything comes up right except the NumPass value...i get the ? value by saying;
    sorgulama.setInt(4,Integer.parseInt(request.getParameter("NumPass")));
    But it won't display the values that are >=...Displays nothing...
    Also the NumPass value is "int" type in the database...
    Any idea to solve this...kinda urgent ..

    Log the parameters being used in your application.
    Run the query directly against the database using the parameters your app is using, verify you find something.

  • Combo Box, Converting string to int

    The user is able to select the month, year etc for a TimerTask using a combo box.
    The problem I have is converting say, "January" to an integer 0 for use to set in a calendar for the date.
    The combo box is populated with every month but i cannot link it with the int variable "month" where 0= january, 1- feb etc for use in the TimerTask.
    In other words, when the user selects "January" in the combo box i want the integer value for the variable "month" to equal 0, for "Febuary", month to equal 1, "March", month equal 2 etc etc.
    Any help would be excellent!!

    if January is the first item in the box, February is the second, all the way to December:
    month = monthComboBox().getSelectedIndex();

  • Help trying to convert string to int

    Hey im trying to input a string in an applet then turn it into a integer so i can use it any ideas?

    long val = Long.parseLong(string);
    if(val > Integer.MAX_VALUE || val <
    Integer.MIN_VALUE) {
    throw new Error("I don't like you :p");
    int intVal = (int) val;No real need to use parseLong and check explicitly the limits. The check for MIN and MAX is performed implicitely inside Integer.parseInt(string, 10), which is called by both new Integer(string).intValue() and Integer.parseInt(string) . When the check fails, it throws a NumberFormatException.
    The only difference between post#1 and post#2 is that the latter it stores the int value in the internal int data member after the call to Integer.parseInt(string, 10), hence the intValue() subsequent call.

  • Converting String to int again...

    telno.addActionListener(this);
    public void actionPerformed(ActionEvent e){
    int x, p, y;
    if(e.getSource()==telno){
    x = Integer.parceInt(telno.getText());
         p = x/10000;
              y = x%10000;
    there's an error 'cannot resolve symbol' when I try to compile.
    Help please, anyone!
    Thanks

    Hi,
    parseInt() and not parceInt() I think.
    Hope it helps
    S�bastien

  • Converting String type to inte type

    Can any one tell me how I can convert an array of Strings into an array of integers??

    it's simple ..... it's like this...
       // some code goes here....
       String num[]={"23", "342", "21", "1"};
        int n[]= new int[num.length];
        for(int i=0; i<num.length; i++)
             n=Integer.parseInt(num[i]); // << -- convert string to int then copied it to int[]
    // rest of your code....

  • Javascript, string to int

    Dear Sir:
    I try to convert string to int in flash javascript:
    temp="120";
    temp2="140";
    temp3=int ( temp );
    but I got a message "int is not a function", can somebody tell me how to do this?
    also, what if I want convert number back to string?
    thanks a lot!

    use:
    temp="120";
    temp2="140";
    temp3=Number ( temp );
    // to convert to a string, use:
    var temp4:String=String(temp3);
    // or
    var temp5:String=temp3.toString();

  • Optimize function to correct a string to be converted to number

    Hi,
    I have imported almost 6.5 milion rows into a table (using sql loader) from a flat file (which contains the NUL caracter (ASCII 0) - not space, not NULL). To make the load easier I set the datatype as VARCHAR2 for all columns. For columns with string data I used a TRIM(REPLACE(field,' ','')) to get rid of the NUL and it works.
    But for the column that must be converted to numeric I am trying to use to_number () function and it fails because the numeric data is mixed with other characters.
    To solve this problem I created this function :
    CREATE OR REPLACE
    FUNCTION string_to_number
    (p_string_source IN VARCHAR2 ) RETURN VARCHAR2 IS v_output_string varchar2(150);
    -- This function takes a string as parameter and has 2 outputs:
    -- 1. If the source string cannot be converted to number throw 'Error' as the output message to identify the line with the issue
    -- 2. A string that can be converted successfully as Number;
    -- The necessity of this function came up after an import from a flat file where the resulted string contained strange characters shown as spaces
    --check if '-' is exists and is on the first position or if in the source string exists more than one '.'
    -- ASCII codes accepted in the string :
    -- 45 '-' ; 46 '.' ; from 48 (0) to 57 (9)
    BEGIN
    DECLARE v_minus VARCHAR2(1);
    v_dot INTEGER;
    BEGIN
    SELECT substr(p_string_source,1,1) INTO v_minus FROM dual;
    SELECT instr(p_string_source,'.',1,2) INTO v_dot FROM dual;
    --check if '-' is exists and is on the first position or if in the source string exists more than one '.'
    -- ASCII codes accepted in the string :
    -- 45 '-' ; 46 '.' ; from 48 (0) to 57 (9)
    IF v_minus NOT IN ('-','.','0','1','2','3','4','5','6','7','8','9')
    -- or there are two dots '.' in the string
    OR v_dot <> 0
    THEN v_output_string := 'Error';
    ELSE
    BEGIN
    -- for every character of the string we'll check if it's a number to add it to the outcome string;
    -- if it's not an accepted character it will be ignored
    DECLARE v_length_source int := length(p_string_source);
    v_counter int :=1;
    v_add_in_number VARCHAR2(1);
    BEGIN
    FOR v_counter IN 1..v_length_source LOOP
    BEGIN
    SELECT SUBSTR(p_string_source,v_counter,1) into v_add_in_number from dual;
    IF v_add_in_number IN ('-','.','0','1','2','3','4','5','6','7','8','9')
    THEN v_output_string := v_output_string ||v_add_in_number;
    END IF;
    END;
    END LOOP;
    END;
    -- in case the string is in format '.00034' we'll add a 0 in front of the string to be accepted as argument by TO_NUMBER function
    IF v_minus = '.'
    THEN v_output_string := '0'||v_output_string;
    ELSE
    BEGIN
    v_output_string := v_output_string;
    END;
    END IF;
    END;
    END IF;
    END;
    RETURN v_output_string;
    END;
    The main idea is to check every string (the parameter will be the value from the Amount column) for permitted characters that compose a numeric value:
    1. To begins with numeric, '-' or '.'
    2. To have only one '.' (as a decimal separator);
    3. To compare every character of the string with the permitted ones - the non-compliant will be rejected
    This way the resulting string (v_output_string) will be successfully converted to number
    I admit that I don't have much experience using PL/SQL that is why I am asking your help to optimize this function to improve its performance. Could you help me on this, please ?
    TIA,
    JohnP
    Edited by: petresion on 04-Oct-2012 01:33

    Perform a function here on all 6.5 million of rows will never be efficient.
    I would modify Peter's approach a little bit,
    1. Load directly into staging t1 without any checking (or create an external table)
    2. Transfer from t1 to a list partitioned t2 with list values in ('yes', 'no','null','other')
    --simple check using translate()
    3. Apply your special function only on rows in the 'other' partition (hopefully much fewer rows left)
    --other checks                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • Leading Zeroes are lost when convert from string to int

    What I'm trying to do is simple yet the solution has seemed difficult to find.
    I have a system that requires 4 digit numbers as "requisitionNo". The system uses JSPs and accepts the 4 digit number that the user inputs (fyi - duplicate handling is already managed). The input number (rNumber) is of STRING type and in the action (using struts) is converted to an int:
    int requisitionNo = Integer.parseInt(rNumber);At that very line the issue is that when the user inputs a number with leading zeros such as: "0001" the 3 leading zeros are chopped off in the INT conversion. The application validation kicks in and says: "A 4 digit number is required" which is by design. The work around has been that the user has been putting in number that start with 9's or something like that, but this isn't how the system was intended to be used.
    How do I keep the leading zeroes from being lost instead of saving a number "1" to the database how do I keep it saving "0001" to the database? Would I just change everything to STRING on down to the database? or is there another number type that I can be using that will not chop off the leading zeroes? Please provide short code references or examples to be more helpful.

    Yeah, I have to agree here that leading zeroes make no sense. I figured that out when I started to look into this problem. The only requirement that exists is that the user wants it to be a 4 digit number due to some other requirement they have themselves.
    So what I'm gathering from what I've read in the responses thus far is that I should change the validation a bit to look at the STRING for the 4 required digits (which are really 4 characters; maybe I should add CLIENT side numeric validation; currently its doing server side numeric/integer validation; or maybe change up the server side validation instead???) and if they are ALL GOOD then let the application save the int type as it wants to. IE: Let it save "0001" as just "1" and when I come back to DISPLAY this saved number to the user I should append the string of "000" in front of the 1 for display purposes only? Am I understanding everyone correctly?

  • 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

  • Converting string format of a number to numeric.

    Hi,
    I use the NumberFormat classes to convert a number to it's string formatted representation in the given locale. How do I achieve the opposite?
    I mean, how do I convert a String value of +"23,233,23"+ to an integer value 2323323?
    Thanks.

    I use the NumberFormat classes to convert a number to it's string formatted representation in the given locale. How do I achieve the opposite?Have a look at the parse() method of NumberFormat.
    ~

Maybe you are looking for

  • How do I call a sub vi and have the window appear in a certain location that I specify?

    I have a vi that will be used to control a robot. I am using a sub vi that is a sort of joystick-drag the mouse to move the robot. This pops up as a dialog when the user moves the mouse over a graph, but it appears in the middle of the screen. I want

  • How can I change IOS7 to be higher contrast and bolder?

    How can I change IOS7 to be higher contrast and bolder?  I can hardly read the timer/alarms among other things?  I really am not thrilled with the new delicate look and I'm a woman.

  • TCode in CRM to upload a file

    Is there any tcode in crm to upload a file in application server for example in R/3 we have CG3Z is there any way Please i need only Transaction code

  • Disable auto switching WAN/LAN/WI-FI

    Hi, I want 2 lan card on same laptop therfore I purchased USB lan card when i connect lan cable to Gigabit ethernet the USB lan automatically get disconnected i also tried with diffrent profile but no success Please let me know the steps how to disab

  • Play multiple movies in same window area

    Hello, I'm sure this question has come up before, but couldn't find it. On my html page I want to have a number of links to my Captivate movies down column on left, and then one movie container on the right, so each time a movie link is clicked, the