Help keeping leading zero String- Long

Hello
I wonder lets say I have a String "09090" how do I convert this String to a Long and keeping leading zero so the Long is 09090?
/D_S

Numeric types like Long (or long) are numbers, not strings, so they have no formatting notions like leading zeroes. If you want to maintain the string "09090" keep the string around, even if you have to parse it as well. By the way, you forgot to describe what your goal is, what you are trying to do and what it has to do with leading zeroes.
One more: Why does this print false?
System.out.println(07070 == 7070);Hint: this generates a compile-time error:
System.out.println(09090 == 9090);

Similar Messages

  • How to keep leading Zeros in a CSV file

    Hi All -
    I am trying to keep leading zeros in CSV file. Ex. I need 00001 but not just 1. I tried formatting the cells but not getting saved. Any advise please.
    Thanks.

    Dear Super Man  ,
    Try using ALPHA Conversion Routine
    ALPHA Conversion Routine
    The ALPHA conversion is used in the BW system for each presetting for character characteristics. The ALPHA conversion routine is registered automatically when a characteristic is created. If you do not want to use this routine, you have to remove it manually.
    The ALPHA conversion routine is used, for example, with account numbers or document numbers
    For more details
    http://help.sap.com/saphelp_nw04/helpdata/en/9b/f9c18f5a07f0459127e9676ae22a54/frameset.htm
    Hope it helps
    Regards
    Bala

  • Convert hex to Decimal and keep leading zeros..

    Hi,
    I hope you can help?
    How to convert hex to Decimal and keep leading zeros
    I read 002C, hex, and I want to convert it to 0044 decimal.
    sscanf (MyNum, "%4x", &DecNum); will only give me 44.
    It have been working up till I started to get leading zeros.
    We will always have a 4 digit hex input in a range
    We must have the leading 00 in this case.
    How is this best done?
    Thanks for the help
    Simon
    Solved!
    Go to Solution.

    Hi,
    I don't really understand your problem. Is this stuff what you need ?
    int main (int argc, char *argv[])
    const char MyNum[] = "002C";
    int DecNum;
    sscanf (MyNum, "%4x", &DecNum);
    printf ("%04d", DecNum);
    getchar ();
    return 0;
    "0044" appears on standard output when printf function executes...

  • Keeping leading zero of an integer

    Wondering if anyone can help me solve this small problem.
    Here's what I had:
    for(int i=01; i<13; i++) {
       String month = "2003" + i;
       System.out.println(month);
    }This gives me the following output:
    20031
    20032
    20033
    20034
    20035
    20036
    20037
    20038
    20039
    200310
    200311
    200312
    However, I want the output to be:
    200301
    200302
    200303
    200304
    200305
    200306
    200307
    200308
    200309
    200310
    200311
    200312
    Then I tried this:
    String year = "2003";
    String month = new String()
    for(int i=01; i<13; i++) {
       if(i<10)
          month = year+"0"+i;
       else
          month = year+i;
       System.out.println(month);
    }The code above gives me the results I want. However, I'm thinking that there has to be a better way to do this. Is there anyway to increment the variable i and kept it two digits? I mean keeping the leading zero until it gets to the number 10? Any ideas?

    the previous poster is right. It's also a little odd how you have things setup, in that you're expressing dates with an unusual approach (most people would use Date or Calendar), but, if you want to keep like you have it, I think this might be the easiest solution:
    int date = 200300;
    for (int i = 1; i < 13; i++ ) {
      System.out.println(date + i);
    }

  • Keeping leading zeros

    I have a series of reports that use Account segmentations that are based on a string of numbers. Unfortunately some of these strings of numbers have leading zeros. (eg. 0023, 0123)
    When the reports are downloaded to excel these leading zeros are lost. Any words of wisdom on how to keep these leading zeros in the report when downloading to excel?

    How would I put the value into double quotes?
    Would this be done under Edit Column Formula?
    If so, I must be doing something wrong. The current column formula is:
    Campaign."Source Code"
    If I change it to:
    "<Campaign."Source Code">"
    I get the following error.
    [nQSError: 10058] A general error has occurred. [nQSError: 27002] Near <Code>: Syntax error [nQSError: 26012] . (HY000)
    SQL Issued: SELECT "<Campaign."Source Code">", Campaign."Campaign Name", Campaign.PICK_0, Campaign.PICK_1, Campaign.PICK_2, Campaign.PICK_3, Campaign.PICK_4, Campaign.PICK_5, Campaign.PICK_6, Campaign.PICK_7, Campaign.PICK_8, Campaign.PICK_9, Campaign.Status, Campaign.TEXT_31, Campaign.TEXT_32, Campaign.TEXT_33, Contact."Contact First Name", Contact."Contact Last Name" FROM "Campaign Response Analysis"
    Please advise.

  • Leading zero no longer showing up for hour in clock.

    I know this is a nitpick, but the leading zero for the hour no longer shows up in the menu bar clock no matter what the settings are. Also there is no option to display the date in numeric form.

    Hello Ben:
    I had not noticed that before, but I do see what you mean.
    I have not played with it, but take a look at system preferences>date & time and then click on +"open language & text."+ Perhaps that might be a way to have the display change. As I said, I have not played with it since I am OK with the current display.
    Barry

  • Keeping leading zero intact  in mail attachment

    Hi All,
    I am sending the excel document into recipients mail id but the leading zero's in the data get truncated.
    I have read so many posts in the forum but did not find any answer to get this done. Some trails i did as follow:
    1. Adding  apostrophes ( ' )  doesn't satisfy my requirement.
    2. Data is good before passing it to mailing function module.
    3. All function module i have tried like SO_NEW_DOCUMENT_ATT_SEND_API1, SO_DOCUMENT_SEND_API1 etc.
       None of them satisfy my requirement.
    Can someone tell  the exact solution?
    Thanks in advance.
    Rudhir Bhaskar

    That's not an SAP email issue though.  I'm sure you'll find that if you open the sent file from a text editor, either from the email client directly or after saving it, that the leading 0's are intact.  Excel is simply interpreting the field as a numeric field upon opening and dropping them.  You need to run the text import wizard and specify the fields as text in order to keep them.

  • Export jsp content to Excel -- how to keep leading zero?

    Hi:
    I am trying to export a JSP content to Excel by using
    response.setContentType( "application/vnd.ms-excel" );
    response.setHeader( "Content-disposition", "attachment; filename=pc.xls" );
    it was working great except my jsp has a field whose value consist of leading zero. i.e. 000XXX. Excel strips the leading zero, but I would like to keep them. Please advise.

    hi Chang,
    Can you please check my thread http://forum.java.sun.com/thread.jspa?threadID=737238&tstart=0
    I think you might know the answer since it is similar functionality but for text files.
    Thanks !

  • Keeping leading zeroes in flat file

    I am loading data from a flat file to a DSO.
    One of the columns in the flat file is data type CHAR with a length of two. The data values will be either 01, 02 or 03.
    When I load the data, the leading zeroes are dropped. Thus, I see 1, 2 and 3 in my DSO. How can I prevent this happening?

    Hi,
    Right Click on that column in Excel file and Formate Cells >Custome> Under Type give "00" and then give the values in column like 01 , 02 .... and save as .csv and close it, immediatly load it, DON"T OPEN FILE, because , if you open it will reset to 1, 2... SO again you need to Right click.....and formare cells..
    Thanks
    Reddy
    Edited by: Surendra Reddy on Jun 24, 2010 4:28 PM

  • How to keep leading zeros using SAP_CONVERT_TO_XLS_FORMAT

    my leading zeros  drop when download using FM-SAP_CONVERT_TO_XLS_FORMAT, how to fix it?

    Hi,
    You can try as below.
    Let's for the 10 digit numeric field, using the function module CONVERSION_EXIT_ALPHA_INPUT, you can get the 10 digit number with leading zeroes.
    Now if you declare the char of 10 in length field in the internal table will be replaced with the above value.
    Now it will be downloaded as required.
    Regards,
    Nishant Malhotra

  • String to double conversion, but keeping leading zeros?

    Hopefully a simple one for you gurus,
    double theValue = Double.parseDouble(aString);works fine, but the input string is say, "08.00", then theValue = 8.0, I want 08.00, how would I go about implementing this?
    tia.

    You will get ur question answered at the following webpage:
    http://java.sun.com/docs/books/tutorial/java/data/decimalFormat.html
    --DM                                                                                                                                                                                                                                                                               

  • How to keep leading zeros in numeric Keynote entries?

    When I try to enter numbers that start with zeroes in a table, Keynote removes the zeroes. For instance, I type 007 and it gets "corrected" to 7. Also, for instance, when i type false in lower case, it gets changed to FALSE.
    How do I stop this? I found the Auto-correction tab in Preferences, but everything is unchecked there except for the things that deal with email and hyperlink underlining.

    Ok, naturally I found it after I posted the question. I go to Table in the inspector window and change Cell Format from Automatic to Text.

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

  • Remove leading zeros from a string

    Hi,
    I have a string with some numeric value.
    e.g.
    String a = 54890001
    I want to make it 10 digits long by padding zeros at the begining
    Now a = 0054890001 ( this is for display purpose ) I know how to do it.
    Now How can strip these leading zeros from this number to get back the actual number. The user sees this 10 digit number and he can change it to something like 0067490001. Now I want to strip these leading zeros.
    and i shd get 67490001.
    In other words, how to strip leading zeros from a string ?
    Thanks for help
    Vinod

    I would try two things: First, just try a straightforward parsing of your String using the Integer.parseInt() method. This is only my first suggestion because the number could be interpreted as octals; only testing will really tell. Second, try a method like this:
    public static String removeLeadingZeros(String str) {
        if (str == null) {
            return null;
        char[] chars = str.toCharArray();
        int index = 0;
        for (; index < str.length; index++) {
            if (chars[index] != '0') {
                break;
        return (index == 0) ? str : str.substring(index);
    }Shaun

  • APD - How to remove leading zero's in a String?

    Hello All,
    I have been stumped by this challenge for a few hours now, so would appreciate your suggestions.
    I am using APD to produce a CSV file where the source is a query. The output requires 0MATERIAL and this is delivered by the source query. The issue is that the CSV file must not retain any leading zero's that may exist in the 0MATERIAL value.
    e.g.
    example #      original material code     desired output
    =========     ======================     ==============
    a            000000000000015931      15931
    b            000000000001001037      1001037
    c            000000000008945420      8945420
    d            000000000080889200      80889200
    e            0000000000L0293500      L0293500
    Initialy, I believed I could simply output the value of 0MATERIAL to an integer field. This would remove all leading zero's but not all 0MATERIAL codes are purely numeric in value (see example (e));
    Someone had a similar requirement w/ SQL Server and solved it by replacing all zero's with a space, trimming leading spaces, then replacing remaining spaces back to zero's! [url]http://www.sql-server-helper.com/functions/trim-leading-zeros.aspx[url]
    So the logic is something like this:
    1. Replace each 0 with a space: REPLACE('0','',[0MATERIAL])
    2. Use the L_TRIM string function to trim leading spaces: L_TRIM(<result from Step #1>)
    3. Replace all spaces back to 0: REPLACE('','0',<result from Step #2>)
    Formula Builder looks like this:
    L_TRIM(REPLACE_ALL('0','',0MATERIAL))
    I attempted this using the
    REPLACE()
    function (available in the APD Formula builder) to replace all zero's with an empty string. This too created a problem because as in examples (a) through to (e), the function replaces all zero's in the string not just the leading ones! e.g.
    REPLACE('0', '',000000000001001037)
    gives 1137 ! 
    The problem here is that when you specify a space in the
    REPLACE()
    function by saying
    it thinks you meant no spaces at all! Therefore I am no longer able to execute step 3! 
    I'm stumped now and would appreciate the communities help on this.
    Thanks,

    Thanks Akshay,
    I took 0MATERIAL as the source field
    I specified ZMATLWOLDZERO as the target field (type same as 0MATERIAL).
    In the code section i wrote this:
      DATA: ls_source TYPE y_source_fields,
            ls_target TYPE y_target_fields.
      loop at it_source into ls_source.
        move-corresponding ls_source to ls_target.
        call function 'CONVERSION_EXIT_ALPHA_OUTPUT'
          EXPORTING
            output = ls_target-ZMATLWOLDZERO
          IMPORTING
            input  = ls_source-material.
        append ls_target to et_target.
      endloop.
    compiles fine but on test execution, the code termnates saying that "Incorrect parameter with CALL FUNCTION"
    Forgive me this is a first attempt I have tried but I fear my logic is incorrect in the code somewhere...

Maybe you are looking for