Need help with formatting a number

hi all,
the problem i am having has been a hot topic over time in java. i have an integer say 123. i want to convert this to a string of 10 characters. how do i pad the first seven spaces with blanks. ex. " 123" in c++ you can use sprintf. how do i do this in java. i have seen mention of NumberFormat but being new to java cannot figure this class out. any helpful code would be much appreciated.
thanks

That would certainly works but it is not the most efficent method to achive the goal since it discards String objects left right and center (especially if you want more than 10 padding spaces)
public String pad(Integer i) {
String value = i.toString();
StringBuffer buff = new StringBuffer();
for( int i = 0, n = ( 10 - value.length ); i < n; i++ ) {
buff.append( " " );
return buff.toString() + value;
}

Similar Messages

  • I need help with my serial number.  I downloaded soundbooth cs3 to restore my downloaded puchase, but my serial number is not being accepted.  I have 16 more days to resolve this.

    I need help with my serial number.  I downloaded soundbooth cs3 to restore my downloaded purchase, but my serial number is not being accepted.  I have 16 more days to resolve this.  I don't need tech support, I just need the software I purchased to work for me.  That's not to much to ask, is it?  Can anyone from adobe help me please?
    Chris

    Error "The serial number is not valid for this product" | Creative Suite

  • Need Help with Format/Partition.. using cmd

    Okay guys.. Im kinda sick of trying to get my Recovery to work. Seems like its about to finish and everything is perfect.. then suddenly I get an error message saying that Recovery didnt work, or something like that..
    I figured I might as well try starting with a fresh hard drive, then trying the recovery again..
    So someone told me that if I have the HP Recovery disks, then I would be able to try them, even on a brand new hard drive, or a formatted one or whatever..
    Is this true?
    If so, then what I am asking you guys, is, if there is anybody that would be able to help guide me thru the steps needed, in order for me to Format my hard drive, & then partition it or whatever…
    & I wanna be able to do all this, using cmd (command prompt)
    So Please.. anyone.. your help would be greatly appreciated..
    I have an HP Pavilion dv6653cl
    Thanks!!

    Hi,
    There's no need to pre-format a new Hard Drive - if you perform a 'Factory Reset' using your Recovery Discs, these will perform a quick format and also re-create all the original partitions on the new drive as part of the process.
    A complete guide to using Recovery Discs can be found on the relevant link below.
    Performing An HP System Recovery - Windows 7.
    Performing An HP System Recovery - Windows Vista.
    Performing An HP System Recovery - Windows XP.
    Regards,
    DP-K
    ****Click the White thumb to say thanks****
    ****Please mark Accept As Solution if it solves your problem****
    ****I don't work for HP****
    Microsoft MVP - Windows Experience

  • Need help in formatting a number field with same precision for excel output

    I am trying to get the same preciision for a field in RTF template when the output is in EXCEL
    i.e. same number of digits after decimal. So, I would like to show 150 as 150.00 and 123.2 as 123.20 etc !! Is there a way to do it. the Built in formatting will not display 150.00 for 150 . but if i add $ symbol it will display. But i dont need $ syambol. please help.

    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

  • Need help with Formating a report referenced by a Weblink field

    Hi,
    I have created a report and a field that's a weblink. The field on accounts references the report I've created so that it only returns information on that account and not all accounts in Siebel.
    Now.. the report is formatted in a sequential fashion as most basic reports are formatted.. ex.
    Account Name Number Address City State etc.
    aaaaaa 2222 23 Main NY NY
    I want it to be formatted in a table and not horizontal. Is this possible?
    Like:
    Account Name Number
    aaaaaa 2222
    Address City State etc.
    23 Main NY NY

    Hi !
    On the second step of report design, click on Add view and then Narrative.
    In the narrative part paste the following (it's only an example, you'll have to modify it to fit your needs) :
    <table border="1" cellpadding="5">
    <tr bgcolor="#6666FF">
    <td>Account Name</td><td>Account Location</td>
    </tr>
    <tr>
    <td>@1</td><td>@2</td>
    </tr>
    <tr bgcolor="#6666FF">
    <td>Address</td><td>City</td>
    </tr>
    <tr>
    <td>@3</td><td>@4 @5</td>
    </tr>
    </table>
    This assume that you selected column 1 to 5 with the appropriate datas...
    Regards,
    Max

  • Need help with Rounding a number.

    I have 3 cells each with a formula in them. Please bear with me while I try to explain this.
    Cell D18 contains the formula: =Sum(L18/C5) (L18's value is 58, C5's value is 10), So the value of the cell is 5.8. I need this number to round properly to 6. It does visually on the spreadsheet.
    Cell F18 contains the formula: =Sum(E18/F5) (E18=28, F5=8) So the actual value of F18 is 3.5 which is rounded to 4 visually on the spreadsheet.
    Cell G18 contains the formula =Sum(D18+F18). (D18 visually displays 6, F18 visually displays 4, therefore G18 should display 10). G18 actually displays 9. For some reason the calculations are still based on the actual calculations of D18 & F18, instead of the rounded displayed numbers. How do I get G18 to display the correct number of 10, rather than the rounded down number of 9?
    I'm sure there's a simple fix that I'm just not understanding. I hope I explained my problem well enough, I'd appreciate any help I can get. These numbers are to calculate insulin dosage, so I need to be sure the math is correct.
    Thanks in advance for any help!

    yvieinca wrote:
    I have 3 cells each with a formula in them. Please bear with me while I try to explain this.
    Cell D18 contains the formula: =Sum(L18/C5) (L18's value is 58, C5's value is 10), So the value of the cell is 5.8. I need this number to round properly to 6. It does visually on the spreadsheet.
    Cell F18 contains the formula: =Sum(E18/F5) (E18=28, F5=8) So the actual value of F18 is 3.5 which is rounded to 4 visually on the spreadsheet.
    Cell G18 contains the formula =Sum(D18+F18). (D18 visually displays 6, F18 visually displays 4, therefore G18 should display 10). G18 actually displays 9. For some reason the calculations are still based on the actual calculations of D18 & F18, instead of the rounded displayed numbers. How do I get G18 to display the correct number of 10, rather than the rounded down number of 9?
    The explanation is that you don't understand what you are doing.
    When you ask numbers to display 0 decimal, you don't ask it to round the contents but to display the rounded value.
    A contents remains 3.6 but the display is 4
    an other contents may be 3.6 too displaying 4
    When you sum, you ask number to add the contents (3.6 + 3.6) which is 7.2 and you ask it to display the rounded value of this result. So you correctly see 7 not 8.
    If you want to get what you described, you MUST force Numbers to round.
    First,I don't understand how you may invent such a silly thing like =Sum(L8/C5)
    You are asking Numbers to sum the result of the division L8/C5 to nothing.
    The correct syntax would ask it to calculate the quotient, no less no more.
    =L8/C5
    but here we need to round so, in D18, enter
    =ROUND(L8/C5,0)
    in F18, enter
    =ROUND(E8/F5,0)
    In G18, =Sum(D18+F18) is silly too.
    You are asking nummber to sum (D18+F18) and nothing.
    The correct formula may be:
    =SUM(D18,F18)
    or
    =D18+F18
    Yvan KOENIG (from FRANCE samedi 13 juin 2009 18:05:33)

  • Need help with a reverse number method

    hey all..
    i have this program which should return the integer reversed ..
    i have done this program using methods.. but the problem is if the
    number endes with 0 when it reversed the output doesn't contain the number 0
    for example:
    input
    123450
    output
    54321
    where before the 5 there should be 0
        This program that reads an integer and then calls a method
          that receives an integer and returns the integer with its digits reversed.
          Main prints the resulting integer.
       import java.util.Scanner; // program uses class Scanner
        class Sh9q4
           // main method begins execution of Java application
           public static void main( String args[] )
          // create Scanner to obtain input from command window
             Scanner input = new Scanner( System.in );
             int number; // The number entered by the user
             System.out.println("Enter an integer"); // prompt for input
             number = input.nextInt(); // read the the integer
             reverse (number); // print the method reverse
          } // end method main
           public static void reverse ( int num )
             int lastDigit; // the last digit returned when reversed
             int reverse = 0;
             do
                lastDigit = num % 10;
                reverse = (reverse * 10) + lastDigit;
                num = num / 10;
             while (num > 0);
             System.out.println("The integer with its digits reversed " + reverse); // print the integer reversed
          }// end method reverse
       } // end class Sh9q4thanks for your help :)

    If you need the leading zero to display, then you will have to do as Keith recommended and convert the input number to a String, then reverse that String and print it as a String.
    A number is a number is a numerical value, and there is no difference between the value of 054321 and 54321 except when written as a literal, when the first is an octal, and the second a decimal, value.
    If you are still confused, plug in these few lines of code and run them:String str = "012345";
    int x = Integer.parseInt (str);
    System.out.println(str);
    System.out.println(x);db

  • Need help with formatting a software RAID 5 array with xfs

    Hi,
    i'm tying to format a software RAID 5 array, using the xfs filesystem with the following command:
    # mkfs.xfs -v -m 0.5 -b 4096 -E stride=64,stripe-width=128 /dev/md0
    but all I get is the attached error message. It works fine when I use the ext4 filesystem. Any ideas?
    Thanks!
    http://i.imgur.com/cooLBwH.png
    -- mod edit: read the Forum Etiquette and only post thumbnails http://wiki.archlinux.org/index.php/For … s_and_Code [jwr] --

    Sorry I numbered them to show the flow of information, this was also just a place for me to store info as I worked through it. I managed to get it to work by creating a partition that takes up the whole drive and is actually 22 GB larger than all the other drives (since I found out that the had root, swap and home partitions that are no longer needed).
    I should be able to resize the other partitions without a problem, correct? They're EXT4. Should I unmount the raid array and do them individually, remount the array, let it sync and do the next? Or just unmount the array, resize all of them, mount it and let it sync?

  • Need help with formating numbers

    public void returnDollars()
              double dollar;
              dollar=amountr-amount;
    NumberFormat fmt = NumberFormat.getNumberInstance();
              System.out.println(fmt.fomat(dollar));
    there is my code.....now lets say
    amountr = 10
    amount 8.5
    now when i print my dollar amount i want it to show up as 1 not 1.5 or 2. So in other words format it with no decimals and not round up at the same time.
    Help would be appriciated...thanks

    well...after 8 hours of trying to get it working i did it.....here it is ...........I'm sure there are many ways to make it smaller.
    import java.text.*;
    import java.io.*;
    import java.io.BufferedReader;
    import java.io.InputStreamReader;
    import java.io.IOException;
    public class Cashier
    double amount;
    double amountr;
    double dollar;
    double amountleft;
    double quaters;
    double test;
    double dimes;
    double pennies;
    public void getAmount()throws IOException
         BufferedReader console = new BufferedReader(new InputStreamReader(System.in));
              System.out.println("Please enter amount due:");
              String input = console.readLine();
         amount = Double.parseDouble(input);
    System.out.println("Amount due = " + amount);
         public void recieve()throws IOException
    BufferedReader console = new BufferedReader(new InputStreamReader(System.in));
              System.out.println("Please enter amount recieved :");
              String input = console.readLine();
         amountr = Double.parseDouble(input);
    System.out.println("Amount recieved = " + amountr);
         public void returnDollars()throws IOException
              double check = amountr-amount;
              dollar=amountr-amount;
    DecimalFormat fmt = new DecimalFormat("##");
    String s = fmt.format((double)(long)dollar);
    double d = Double.valueOf(s).doubleValue();
    amountleft=check-d;
         System.out.println("Dollars to return " + s);
    public void returnQuaters()
         quaters= amountleft/.25;
         double check = quaters;
    DecimalFormat fmt = new DecimalFormat("##");
    String s = fmt.format((double)(long)quaters);
    double d = Double.valueOf(s).doubleValue();
    fmt.setMaximumFractionDigits(2);
    String dol = fmt.format(amountleft);
              //System.out.println(dol);
              double e =Double.valueOf(dol).doubleValue();
    e= e-2*(.25);
    amountleft=e;
         System.out.println("Quaters to return: " + s);
         public void returnDimes()
         dimes= amountleft/.1;
         double check = dimes;
    DecimalFormat fmt = new DecimalFormat("##");
    String s = fmt.format((double)(long)dimes);
    System.out.println("Dimes to return: " + s);
    double d = Double.valueOf(s).doubleValue();
    fmt.setMaximumFractionDigits(2);
    String dol = fmt.format(amountleft);
              double e =Double.valueOf(dol).doubleValue();
    e= e-1*(.1);
    fmt.setMaximumFractionDigits(2);
    String dola = fmt.format(e);
              double t =Double.valueOf(dola).doubleValue();
    amountleft=t;
              public void returnNickles()
         double nickles = amountleft/.05;
              double check = nickles;
    DecimalFormat fmt = new DecimalFormat("##");
    String s = fmt.format((double)(long)nickles);
    System.out.println("Niclkles to return: " + s);
    double d = Double.valueOf(s).doubleValue();
    fmt.setMaximumFractionDigits(2);
    String dol = fmt.format(amountleft);
              double e =Double.valueOf(dol).doubleValue();
    e= e-1*(.05);
    fmt.setMaximumFractionDigits(2);
    String dola = fmt.format(e);
              double t =Double.valueOf(dola).doubleValue();
    amountleft=t;
         public void returnPennies()
              double pennies = amountleft/.01;
    DecimalFormat fmt = new DecimalFormat("##");
    String s = fmt.format((double)(long)pennies);
    System.out.println("Pennies to return: " + s);
         public static void main(String[] a) throws IOException
              Cashier cash = new Cashier();
              cash.getAmount();
              cash.recieve();
              cash.returnDollars();
              cash.returnQuaters();
              cash.returnDimes();
              cash.returnNickles();
              cash.returnPennies();

  • Need help with format and reinstall of leopard

    hey guys. I am having major problems with my MacBook. I have been using it for over a year with no problems, however last night it crashed big time. Data loss isnt an issue, as I did a full backup the night before. I need to know if it possible to format the hard drive through the terminal. I have been trying to do so with no luck as the drive continually gives me the error "resource busy." it does this in terminal, single-user mode and disk utility off of the DVD. I am pretty savvy with all but the most complicated terminal work. How do you check running processes and end them through the terminal? I think if I can fix that, I might be able to format the drive. Its havng b tree and leaf errors through fsck. It may need to be replaced. Let me know what is this best way to format the drive and get it back to a blank slate through the terminal and fix the resource busy problems.

    If you boot the "offending" Mac as a FW target disk, there should be no permissions issues on that drive. Permissions are controlled by the OS which will not be loaded when the computer is booted into target disk mode. If the target disk is connected to a running Mac, you should be able to treat the drive just like any other external FW drive. At that point, you should be able to delete any existing partitions on the drive, create (a) new one(s) and "zero out" the drive. There is an "Ignore permissions on this drive" option that should be selected. I can't imagine any logical reason that you could not reformat the drive in this manner.

  • Need help with formating

    Hello:
    I have created a survey form with approx 50 questions and 4 choices (Never, Rarely, Sometimes, Often).  I am saving it as a .pdf to email to patients and not including the "submit" button.  I have a header and text box (instructions) above the questions.  When I save the document, it inserts a page break after my text box, which is leaving a lot of blank space on the first page.  How do I correct that?
    P.S.  I have tried decreasing the pixel width but then get a warning message "rating scale cropped".
    We are a paid member of Forms Central.
    Hope this makes sense...
    Margaret Swift

    Eventhough you distribute your form as a HTML (web) form you can still view the Page View by switching the view with the control in the bottom right corner so you have an idea what the PDF will look like when you "Download the Response as PDF".
    Open you form
    Go to the Design Tab
    Switch to Page View
    Once in Page View you might see which content is truncated (if you scroll down you might see a red rectangle over some content)
    What you need to do with Rating Scale is separate them in multiple fields.
    For example if you have a Rating Scale with 30 rows of questions change it to be two Rating Scale fields with 15 row each. Make sure you export your data first because changing the Rating Scale might delete some columns in your Response Table if you already have gather data.
    You can also try to make the font smaller. That might made ehough room for your Rating Scale to fit completely on one page.
    Also note that the Page Break you add to the Page View doesn't affect the Page Break on your web fillable form.
    Gen

  • Need help with formating in a dashboard prompt

    Hi
    This should be an easy one. I'm creating some dashboard prompts and been looking on the Sample OBIEE and some prompts there. Well, what I would like to do is a prompt so simple as:
    Prompt Label:
    - alt1
    - alt2
    - alt3
    - and so on ...
    Have you seen what I've done? I want the Label of the prompt to be bold but the data inside, the alternatives should be normal.
    What I do is that go to the Dashboard prompt, create it and so on and on the lower part of the Dashboard prompt edit pane "Display" I click on the pencil ... "Edit" ... go to "Format" and in there I choose "Style: Bold" ... the thing is that both Label and Alternatives turn Bold for me ...
    What am I doing wrong?

    Hi,
    If you are using 11g then keep the prompt in a section and you can add section title and you can format it accordingly. But keep the name in the label as a BLANK.
    And if you are using 10g then by default the name in the label for the prompts becomes BOLD but the values would be normal.
    Award points if found useful/helpful to you.
    Regards
    MuRam

  • Need help with understanding Skype Number please

    Hi there,
    Not sure if this is posted twice!
    I live in the UK and am trying to offer online coaching through a company in America. I can only offer live chat sessions if I have a US or Canadian number. Is it a Skype Number that I need? Why would it matter which State I choose - will people only be able to contact me from that State?
    Would be really grateful for some clarity.
    Many thanks,
    Solved!
    Go to Solution.

    Hi, Tracy255, and welcome to the Community,
    Unfortunately, for several reasons, Skype Numbers are not available in Canada.
    The concept of any virtual number is to provide a way for people who do not have accounts on the service to contact the subscriber, but using a fixed line or land line number.  In the case of Skype Numbers in the United States, the best scenario would be to have a number set up where most of your customers would be able to call without incurring high toll charges or ideally no toll charges.  Of note, not all states participate in the Skype Number program, again for any number of legitimate reasons.
    Skype does not offer "toll-free" numbers.
    Here is a link to the library of FAQ articles related to Skype Numbers seeing as I believe you will have more questions than I have provided information for!
    https://support.skype.com/en/category/ONLINE_NUMBE​R_SKYPEIN/
    Please pardon the naming convention confusion; today's Skype Numbers where formerly known as Online Numbers or Skype In.
    Regards,
    Elaine
    Was your question answered? Please click on the Accept as a Solution link so everyone can quickly find what works! Like a post or want to say, "Thank You" - ?? Click on the Kudos button!
    Trustworthy information: Brian Krebs: 3 Basic Rules for Online Safety and Consumer Reports: Guide to Internet Security Online Safety Tip: Change your passwords often!

  • Need HELP with Format again !

    Hi there,
    I am getting mad....because I can't find what I do wrong....and I thought that I had all understood...
    1) I shot a bunch of clips with a Sony HD. According to Mediainfo, clips are 1440x1080, as I expected from my movie camera settings
    2) I create a new FCP project. Choose 1440x1080 60i. Sequences indeed show 1440x1080, 29,97 fps
    so far so good ...
    3) when I drag the clips in the timeline, I get thje message saying that "to get best results sequence setting should be modified to match clip setting"
    After checking all previous settings...I am left to say "yes"
    4) Then I export as a QT with QuickTime making sure that I select 1440x1080 60i and get a QT file
    5) according to Mediainfo the QT file is 1416x1062, 29,97 fps !!!!!!
    Could someone please explain why I get a different format ? and what I should check if I do something wrong with my settings ?
    Many thanks in advance !!!
    Ivan

    Hi Ivan,
           The dimensions you are seeing in Quicktime player are the "current" dimensions. If you look at the "normal size" it should be 1440 X 1080. Your frame rate is correct.
    DM

  • [SOLVED] need help with formatting in python

    HI, i have this little bookmark script in python: https://github.com/carnager/robot/blob/master/robot
    there are 2 functions that spit out the same output, but one is filtered (listAll and listURL)
    while listAll is formatted nicely, I couldnt manage to format the listURL stuff.
    for convinience here are both functions:
    def listURL(args):
    bookmarkfile = open(str(bmarks), 'r')
    bookmarks = json.loads(bookmarkfile.read(), 'r')
    bookmarkfile.close()
    if args.group:
    url = [bookmark['name'] + " " + bookmark['url'] + " " + ', '.join(bookmark['tags']) + " " + bookmark['group'] for bookmark in bookmarks if bookmark['group'] == str(args.group)]
    print("\n".join(url))
    if args.tag:
    url = [bookmark['name'] + " " + bookmark['url'] + " " + ', '.join(bookmark['tags']) + " " + bookmark['group'] for bookmark in bookmarks if args.tag in bookmark['tags']]
    print("\n".join(url))
    def listAll(args):
    bookmarkfile = open(str(bmarks))
    bookmarks = json.loads(bookmarkfile.read())
    bookmarkfile.close()
    if args.urls:
    for x in bookmarks:
    print("%-40s %-90s %77s %15s" % (x['name'], x['url'], ', '.join(x['tags']), x['group']))
    else:
    for x in bookmarks:
    print("%-40s %77s %15s" % (x['name'], ', '.join(x['tags']), x['group']))
    Any idea how to format listURL too?
    Last edited by Rasi (2014-08-24 00:36:40)

    Use the same format in both functions.
    def listURL(args):
    bookmarkfile = open(str(bmarks), 'r')
    bookmarks = json.loads(bookmarkfile.read(), 'r')
    bookmarkfile.close()
    fstr = "%-40s %-90s %77s %15s"
    if args.group:
    for x in bookmarks:
    if x['group'] == str(args.group):
    print(fstr % (x['name'], x['url'], ', '.join(x['tags']), x['group']))
    if args.tag:
    for x in bookmarks:
    if args.tag in x['tags']:
    print(fstr % (x['name'], x['url'], ', '.join(x['tags']), x['group']))
    If you want to use Python 3 style formating (which also works with recent versions of python 2), substitute the following:
    fstr = "{:40s} {:90s} {:77s} {:15s}"
    print(fstr.format(x['name'], x['url'], ', '.join(x['tags']), x['group']))

Maybe you are looking for

  • The folder 'itunes' is on a locked disk on windows

    Hello Support, i am getting this msg on my win7 when trying to open iTunes. the folder 'iTunes' is on a locked disk or you dont have write permission for this folder. please help what to do? thanks

  • Javadoc @throws clause at a class level for all methods

    hello If all my class's methods throw the same RuntimeException for the same reasons, is there a way to put a @throws clause at class level? I mean, I don't want to duplicate my comments for each of the methods I have. Say I want to add extra informa

  • CiscoWorks LMS 3.2 Cross Site Deployment query

    Hi, We currently have LMS 2.6 installed at Manchester Airport. We would like to upgrade this to 3.2 and deploy the same product at 3 other Airports within the group. Ideally I would like to centralise all reporting and management elements but obvious

  • How to recover passcode

    I set my passcode this morning, and ever since then I can't remember it. If anyone knows any possible ways at all to recover it with or without Itunes, please let me know asap!

  • Adding a change password link in a custom portlet

    Hi, Does anyone know how to add a change password link in a custom portlet? the custom nav UI we have does not show the my account link, we want to hide this complexity for external users, but we still want them to be able to change their password. I