Format a number with leading ones

How do I format a number with leading ones or twos?
This is what I'd do to format a number with 8 leading zeroes:
String.format("%08d", 160)But, if I do the same with 8 leading ones, it does not work the way that I expect:
String.format("%18d", 160)I'd appreciate your help.
Thanks.

933581 wrote:
>
What are you expecting?
>
I expected that "%18d" would pad with 1s.You assumed
mmm I just thought that while "%08d" pads with 0s, the same would happen if I used "%18d" to pad with 1s.But if you would have looked at the javadoc of that method you would have very quickly known this was not the case and you wouldn't even had to create this thread. Why operate on guesswork when it is so easy to know reality? :(

Similar Messages

  • How can I format a number with leading zeros?

    I need to convert an int to occupy exactly 3 positions in a StringBuffer... I need the space in the StringBuffer to be filled with leading zeros where appropriate. Can anyone show me how to do this correctly please ?
    At the moment I am using a pretty dumb workaround to fill the target with "000" first and then parse the int into either 1 2 or 3 positions depending on its value ... it works, but there must be a more correct way to do this ...
    Thanks in advance ...

    Have you had a look at the class java.text.DecimalFormat? It does exactly what you want... example:
    StringBuffer sb = new StringBuffer();
    DecimalFormat format = new DecimalFormat("000");
    format.format(2, sb, new FieldPosition(0));
    System.out.println(sb);
    prints out the string 002.

  • Need formula to take text from one cell, add that to a serial number with leading zeros

    I'm trying to create a spreasdheet cell that simplifies creating videotape Numbers from a job name in cell and appends a serial number with leading zeros, and that would survive an export to EXCEL.
    The result would look like
     A Column
    Job Name
    B ColumnTape #
    Formula needed for B
    ClientName-TapeType-
    ClientName-TapeType-001
    =
    ClientName-TapeType-
    ClientName-TapeType-002
    =
    I've tried using a custom cell format that had the text in front of the (Integer) drag and drop, with three integers and leading zeros.
    That worked, but requires recreating the custom cell format for each client and tape type.
    So, I've used the formula =A2& in order to play around with different things, but haven't hit on something that adjusts for increased numbers and retains the leading zeros.
    I don't mind doing a starter for the first row and then adding +1 in the formulas for the rows below.
    I've done that using the custom cell formats for the first B cell and then using =Bx+1 in the following cells.  It works, but I'm hoping to find something simpler or that can be copied and pasted in multiple rows on one paste.
    Thanks in advance.
    Suggestions much appreciated!
    Ted

    Ted,
    This expression in B will give you the pattern I believe you are looking for:
    =A&RIGHT("00"&ROW()-1, 3)
    Here's a screen shot...
    Jerry

  • Re: Material number with leading zeros (40 char long)

    Hello Experts,
    I am working on SAP ME 6.1.4.15.
    I am having a problem with the material number appearing in production order / planned order request document in MEINT and failing there since the material it is looking for is with leading zeros (for example 1291 appearing as 0000000000000000000000000000000000001291) - a total of 40 char long.
    But this material exists in ME as 1291 only. Can any one throw any light on this as to what could be the reason and how to solve it?
    Thanks
    Srinivas

    Dear Srinivas,
    SAP Note 1799009 - 'Presence of leading zeros is inconsistent over IDOC thus SAP MEINT cannot handle all inbound IDOC consistently' should help to resolve the problem.
    Regards,
    Alex.

  • EBS check number with leading zeros

    When we upload EBS, we are getting the check number in the record 16 (reference field). But unlike the check number posted in SAP, the check number in the BAI file has 2 leading zeros. Now since check number is coming in record 16, instead of record 88 we are not able to solve this problem through String configuration.
    So, we thought of following solutions(Options):
    1.    Modify the check lot numbers to have two leading zeros plus associated changes like the form and so on.
    2.    Modify the check number in the incoming file u2013 strip the check number with two leading zeros with the use of customer enhancement. (After upload and before posting)
    Can we solve the problem of leading zeros (before the check number) through any configuration steps instead of changing the SAP script form for check(Check lot) or going for customer enhancement.
    Thanks
    Ron

    You are correct, since the check numbers are coming through only in the 16 records and not in the 88 records, you cannot use a search string to resolve the issue with leading zeros.  Also, I do not know of any other configuration that can be used to reformat the reference values in the 16 records.
    The 2 solutions you have listed are both valid options.  Although with the first option (changing the check lots), you would need to make sure the business users approved of changing the check lots before going forward with that option.  And you would still have to manually clear checks that had been issued prior to the check lot change.
    At my company, we went with the second option - using ABAP code to update the check numbers from the file to match those in SAP (we actually had to add leading zeros to the check numbers).  In our case, we had already created a pre-processor program for other re-formatting of the file that was needed prior to loading it into SAP - so we added the check number logic to that.
    However, if you do not have a pre-processor program, I know there is a user exit available for EBS - exit EXIT_RFEBBU10_001, include ZXF01U01.  I have heard of others using this exit to update the check numbers from 16 records.  The exit is called during the FF.5 processing.
    Regards,
    Shannon

  • Format a number with a decimal to show the value but not the decimal point

    I have a value of 129.50 in the DB. I'm using the htp.prn() function to export this value to a txt file. I have the field padded with leading 0s (so it looks like 0000129.50)
    I need to keep the value for the .50 but don't want the decimal point to show up (so I need it to look like 000012950) but can't figure out how to make it keep the value for the .50 but not actually show the decimal point - any ideas? (APEX 4.0 11g)

    Multiply by 100 and remove the formatting. htp.prn (to_char (number_item, '99999999999'));
    Edited by: Kleber M on Sep 14, 2011 5:10 AM

  • How to change serial number with existing one

    dear all,
    Our user create 2 different serial number with same material. let me say A and B. A is the correct serial number but fault historical. and B is the fault serial number but correct historical. The question is can we change the serial number, A with B and still got the correct historical from B
    Regards

    if both the serial number are present in stock & are assigned to a wrong material in this case what you can do is :
    Issue goods through movement 201 alongwith the existing serial numbers (mismatched) against a cost center & GL (Stock Adjustment)
    Receive goods through movement 202 with correct Serial number a cost center & GL (Stock Adjustment).
    eg. in your case :
    Document 1 with movement 201 to remove mismatched Serial number  :
    Material-- Serial Number-----Qty
    A-- 1--
    1
    B--  2--
    1
    Status of both serial number will change from ESTO to AVLB
    Document 2 with movement 202 to assign correct serial number :
    Material-- Serial Number-----Qty
    A-- 2--
    1
    B--   1--
    1
    this way you can resolve serial number mismatch case....

  • Problem with Numbers! Cannot format a number with "1000" separator

    I need to format numbers in cells with the "1000" separator 
    1000.99     should really look like        1,000.99
    Looks like there is no way to do this in Numbers!
    I only found the following work-around:
    When I import a spreadsheet from Excel the formating is there and Numbers will even keep the format as long as I do not delete the cell contect! So to me this means that the functionality is there - it was just forgotten to implement a numbers formatting took in the GUI!
    Of course Numbers is just a scaled down product for iPad and does not really stand up to Excel but this is the most basic function that I expected from a spreadsheet program!
    Anybody experience that problem too or is there another way to get this to work?

    Hey Dell,
    I actually fixed this by using the following which gives the same result.
    ToText(Member#,"#") & "-" & ToText(Account#,"#")
    It would be nice if Crystal Reports Server 2008 was able to detect the field formats used in a report when saved from Crystal Reports. This worked without the formulas in Crystal Enterprise 9.
    Another issue I found on this report was an issue with charts and group headers. If you are using a number on your chart axis it was displaying the number as 9,999.00 and the same for the Group Header. You actually have to create a group header and axis formula specifically converting the number to text with the formula above.
    Thanks,
    Lee

  • Auto increment number with leading zeros

    hello,
    i have data column (serial number) that auto generate from script component, i'm using counter +1 and it successful store the number to my db. but the problem is there any idea to store the number to 00001 rather that 1.
    im using this method in my script component
    dim counter as integer = 0
    counter =counter + 1
    row.NoSerial = counter
    TQ

    Why should you send it through the file? WHy not simply create a calculated column based on identity field or sequence based field (if 2012 version and above)  in the destination table and ignore it from the file altogether. ANyways its going to be
    a sequential auotogenerated value isnt it?
    http://www.sqlteam.com/article/custom-auto-generated-sequences-with-sql-server
    If you want to bring it as  00001 etc you need to make it as varchar and use derived column expressions in SSIS as source is text file.
    I would prefer doing this in sqlserver if its just a sequential number and has no direct relationship to the incoming file data fields.
    Please Mark This As Answer if it solved your issue
    Please Vote This As Helpful if it helps to solve your issue
    Visakh
    My Wiki User Page
    My MSDN Page
    My Personal Blog
    My Facebook Page

  • \b Formatting number with a pattern?

    I am trying to format a number according to the given format by the user. For eg: if the given number is
    1234 and the given pattern is ###.# then my output should be 123.4 Now this is a simple pattern . The input pattern could be even like this ###,##,##.##.

    The DecimalFormat won't change the value of what you give it, just format the value. One way to do what you want is to convert your number to a StringBuffer, then just add a decimal point where ever you want. This won't give you a great deal of flexability, but will solve the problem that you've given.
    long dval = 123456;
    StringBuffer sb = new StringBuffer(String.valueOf(dval));
    sb = sb.insert(sb.length()-2, '.');
    System.out.println(sb.toString());This code can easily be modified to be turned into a method that will take the value and the number of digits after the decimal that will return a String (or double or long) with the new value.

  • How can we keep/save EAN11 number (MEAN-EAN11)  with leading chars '00'

    We're using EAN categoties UC and UA.
    Only difference between UC and UA is that the EAN number with category UA has leading two characters '00'.
    For example if EAN number for UC is '9123456789' then EAN no for UA will be '009123456789' and we want to save it that way in SAP (table MEAN).
    But, the conversion exit for EAN11 stips off thhe leading '00' for the EAN no with UA category and thereby making it same as the one with UC.
    I've played with EAN/UPC attributes in IMG and also used the BADI BADI_EAN_SYSTEMATIC to add leading '00' the but still SAP takes out the leading '00'. 
    Could you please suggest how can I make SAP to keep/save leading '00' for MEAN-EAN11 field when MEAN-EANTP = 'UA'??

    Hi friends,
    My general problem is that I'm using the idoc ARTMAS05 but when to load data delete leading zeros in EAN fields.
    Example of my problem:
    I have a article with this ean code 0056789 and have other article with this ean 00056789, but when to load data the second article it is no stored because shows error message "Ean code already exits". Now I´m finding the way for to be able to load the zeros of the ean.
    I have 23000 article with this problem.
    Thank...

  • Formatting a number element with commas and decimals.

    I have a dataset with numbers.  I already set the column type to "number".
    I want to format the number data with commas and decimals.  I found a way to add decimals, but I'm still very confused how to do commas and to combine that with the decimal formatting.
    Also, how do I apply that to a repeat region in my spry region?
    Any help would be appreciated.  Thank you very much.

    I found this on one of the forum questions.
    Excel dont preserve the trailing zeros.
    try opening the xcel and type 5.0000 and tab out, it wont preserve the trailing zeros after decimal.
    try finding out how to disable the option in excel. if you do that, you will see what you send out from the report.
    But you can try to convert the number into a text by trying to append a space at the beginning. See if that would work.
    Thanks
    Swarna

  • Format a number, pad with spaces

    I want a simple way to format a number into a String, but have it padded with spaces. My code started like this:
    DecimalFormat myFormatter = new DecimalFormat("###.00");
    String output = myFormatter.format(12.5);
    The output is '12.50' when I want ' 12.50' (leading space). There's got to be an easy way to do this!
    Thanks for your help

    What you probably wanted to do was print some numbers in a column (of JTextArea's, for example) so that the decimal points line up.
    I wasted some more time and came up with the following:  String formattedNumber = numberPad(number, "###.00E0");
      static String numberPad(double number, String format) {
        int desiredDecimalPosition = format.indexOf('.');
        DecimalFormat numFormat = new DecimalFormat(format);
        String formattedNum = numFormat.format(Math.abs(number));
        formattedNum = formattedNum.replace('E', 'e');
        int exponentPosition = formattedNum.indexOf('e');
        if (exponentPosition < 0)
          exponentPosition = formattedNum.length();
        formattedNum = formattedNum.replaceFirst("e0", "");
        int decimalPosition = formattedNum.indexOf('.');
        formattedNum = (number > 0 ? " " : "-") + formattedNum;;
        if (decimalPosition < 0)
          decimalPosition = exponentPosition;
        int padding = desiredDecimalPosition - decimalPosition;
        if (padding > 0)
          formattedNum = "        ".substring(8 - padding) + formattedNum;
        return formattedNum;
      }Now it turns out that- despite the fact that I've told DecimalFormat to format precisely 2 digits to the right of the decimal, it sometimes randomly gives me 3, and (less often) 1!
    All this trouble just to try save 16kB of Henrik Bengtsson's sprintf in my jar file...

  • My apple id account is setup with my dads cell phone number, so on my iMessages on my mac i get my dads texts messages, is there anyway to change it so my phone number is the one receiving messages on my mac?

    My apple id account is setup with my dads cell phone number, so on my iMessages on my mac i get my dads texts messages, is there anyway to change it so my phone number is the one receiving messages on my mac?

    Remove his phone number from your AppleID.
    http://appleid.apple.com

  • I formatted and re-installed itunes. now it flashing massage that my ´ipod is synced with another iTunes library. An ipod can be synced with only one library at a time.´ now it is giving 2 options,  1- erase and sync, 2- transfer purchases. what to do?

    i formatted and re-installed itunes. now it flashing massage that my ´ipod is synced with another iTunes library. An ipod can be synced with only one library at a time.´ now it is giving 2 options,  1- erase and sync, 2- transfer purchases. what to do?

    Follow these instructions:
    Syncing to a "New" Computer or replacing a "crashed" Hard Drive: Apple Support Communities

Maybe you are looking for

  • Rigid sleeve macbook pro 13 late 2013

    I'm looking for a rigid sleeve for my macbook pro retina 13", late 2013. One like this: http://store.apple.com/it/product/H9935ZM/A/gauntlet-sleeve-da-13-pollici-per-ma cbook-pro-di-thule?fnode=50&fs=f%3D13inchmacbookproretinadisplay%26fh%3D36c2%252

  • How do i hook up my Inspire T5400 to my game console and satellite?

    I would like to hook up my playstation and my satellite to my speakers but it doesnt have to be at the same time,

  • Contact number of MA FiOS Tech Support

    Hi, What is the correct number FiOS tech support for service in Massachusetts. I dialled the number on the website given by logging into my account: +1 888-553-1555 but when I got through I was told they couldn't access my account and to call +1 866

  • Xquery exception: BEA-382510

    Experts, I am facing this weird issue in OSB, the explanation for the issue is: Whenever the mange instances gets overloaded or even some time when they are running fine, I get this exception BEA-382510 from the message flow. There is no problem with

  • What's the difference between old workbench 2.x configuration and new IFCR configurations?

    I'm an Endeca old-fashioned guy. We moved from workbench 2.1 directly to ToolsAndFrameworks 11, my question is, what's difference between old workbench 2.x and new IFCR conf? Looks emgr_update update_mgr_settings isn't doing the same thing ifcr impor