Parsing a double to make a new string...

Hello,
I am having a problem with this one. I need to format a double so that 1000000.0 can be expressed 1.0 M, or 512000.12 can be expressed 512.0 K etc. etc. any ideas?

Error in the last line. Should read
   public static String format(double d) {
     String[] s = {"", "K", "M", "G", "T"};
     byte b = 0;
     while (d >= 1e3) {
       b++;
       d /= 1e3;
     NumberFormat n = NumberFormat.getInstance();
     n.setMinimumFractionDigits(1);
     return n.format(d) + s[ b ];

Similar Messages

  • Does Oracle XML Parser support double byte charset?

    Hi,
    Does Oracle XML Parser support double byte characters such as Korean or Chinese? If so, please tell me what version and how to construct xml/xsl files (...encoding="???")?
    Thanks for any help,
    Tuan

    Hi Raymond,
    Thank you for your help. It worked when I running in JDeveloper with your posted code. However, when I tried in my real application, it won't work.
    The problem is for localization purposes, my application using some texts display in browsers are saved in Unicode file. Later, application runs and depends on languages setting in browsers, with JavaServlet retrieves those texts and saves in formated xml StringBuffer. Then, using existed XSL Stylesheet file and OracleXMLParser to generate an output HTML.
    It has worked fine with English, France or others (single byte characters), but it can't
    for double bytes character such as Korean or Chinese. I also tried different charset in xml file.
    The following is one of returning errors:
    -- oracle.xml.parser.v2.XSLException: XSL-1004: Error while parsing input XML document (<Line 1, Column 552>: XML-0221: (Fatal Error) Invalid char in text.)
    I run this app in win2000/IIS with ServletExec3.0, JDK1.2.2 and OracleXMLParser v2.0.2.10
    Thank you for any helps,
    Tuan
    <BLOCKQUOTE><font size="1" face="Verdana, Arial">quote:</font><HR>Originally posted by Raymond Hayes Jr ([email protected]):
    Nothing fancy 'cause I'm half asleep but I used your xml/xsl and it seemed to work. No errors anyway. This is what I put together in JDeveloper 3.2
    package demo;
    import javax.servlet.*;
    import javax.servlet.http.*;
    import java.io.*;
    import java.net.*;
    import java.util.*;
    import oracle.xml.parser.v2.*;
    public class CuriosityKilledTheCat extends HttpServlet {
    * Initialize global variables
    public void init(ServletConfig config) throws ServletException {
    super.init(config);
    * Service the request
    public void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    try
    XSLStylesheet xsl = new XSLStylesheet( new URL ("file:///c:\\temp\\input.xsl") , null );
    XSLProcessor xp = new XSLProcessor();
    XMLDocument xd = new XMLDocument ();
    XMLDocumentFragment xf = new XMLDocumentFragment();
    xf = xp.processXSL ( xsl , new URL ( "file:///c:\\temp\\input.xml") , null );
    System.out.println ( "here" );
    xd.appendChild( xf );
    xd.print ( response.getOutputStream() );
    catch ( Exception e )
    System.out.println ( e.getMessage() );
    * Get Servlet information
    * @return java.lang.String
    public String getServletInfo() {
    return "demo.CuriosityKilledTheCat Information";
    }<HR></BLOCKQUOTE>
    null

  • New String(byte[]) taking up huge space?

    Ok. I have a byte[] of approx. 5.000.000 bytes. Whenever, at any point, I try to create a String using this array by new String(array), my memoryusage increases by about 60/65 megabytes. Can anyone please explain me why on earth it's doing this?
    Note also that this space is not freed up by the GC (afterwards).
    Thanks in advance

    Actually, I've discovered some details about the swing textcomponents. They're very bad for 'simply' showing 2mb+ files.
    Check out these bugs; original and "more recent".
    It doesn't quite explain why putting a byte array to a string occupies twice the space, but it does seem to account for the huge memory increase when putting it to a JTextArea.
    String is immutable so it has to copy your char[] to
    a new char[] backing the String. If it used theSure thing, but I'm passing on a byte[] array, and afaik, it's not using this array and should only copy it. Once.
    Oh hey, could it be that the bytes are saved in unicode? That would double the size... and make sense...
    Oh and PS; Maybe you should read this if you really think strings are immutable... (although you are generally correct :))

  • Error:java.lang.Double:method parseDouble(Ljava/lang/String;)D not found.

    Hi ,
    oracle apps version : 11.5.10.2 and database version 11.2.0.2.
    OS version Solaris Sparc 64 Bit.
    We were performing a cloing activity on a new server and now while opening forms we are getting the following error :
    error:java.lang.Double:method parseDouble(Ljava/lang/String;)D not found.Please suggest what has to be done.
    Regards
    Kk

    Hi ,
    D:\Documents and Settings\800045916>java -version
    java version "1.6.0_29"
    Java(TM) SE Runtime Environment (build 1.6.0_29-b11)
    Java HotSpot(TM) Client VM (build 20.4-b02, mixed mode, sharing)We have been struggling with the Solaris server for this. Is something needed from there also or just need to have the latest JRE in the windows client machine.
    Regards
    Kk

  • Can Disk Utility make a "New Image" from a desktop copy of a DVD?

    I have not been able to get Disk Utility to make "new images" of a couple of DVDs. For one of the DVDs, it may have something to do with a hyphen in the title. I haven't a clue why I'm failing with the second of the two DVDs. (Previously, I've had no trouble with about a dozen DVDs so far.)
    Several members of this discussion group recommended me to copy&paste or drag&drop the files from a DVD to a new folder (say on the desktop), and then to drag the resulting new folder into the box in Disk Utility, and then to make a disk image using Disk Utility.
    (Note: While I believe the original DVDs are not encrypted, I ran an experiment to make double sure, by using MacTheRipper first to produce folders containing clean files.)
    However, when I drag the new folder into the box in Disk Utility, and let go of the mouse button, then the folder does not stay in Disk Utility window, but instead springs back to the desktop.
    How can I get Disk Utility to make new images from the new desktop folders?
    Note:
    As a partially successsful work around:
    For one of the two original DVDs - which has only about 3.7GB on it - I can sometimes (only sometimes) succeed in doing without Disk Utility simply by dragging the audio and video files from the new desktop folder onto a blank DVD, and then burning that DVD. However, in an average of about two out of every three attempts so far, my Mac rejects the new disk as unusable during the burn process.
    For the other original DVD - which has about 4.36GB on it - the contents of the new desktop folder won't fit onto a blank DVD. It then gets messy - shrinking the files - so I'd like to avoid all of that by getting DIsk Utility to work properly.

    For the answer, see the following excerpt from my own posting dated 2 May 2006, i.e.:
    "I finally found out for myself (from Disk Utility Help) that to make a new image from a file/folder, rather than dragging the folder to the Disk Utility pane, in the top menu bar in Disk Utility you select Images/New/Image from Folder."

  • I am trying to make a subclip but it makes a new sequence

    When I mark in and out points and click on "make subclip", it instead makes a new sequence.  Any ideas?

    I just discovered I need to double click on the clip first! Problem solved.

  • Instance a new String

    hello guys
    i have a statement like:
      "select * from myTable where name='NameX' and sex='SEX' and " it is generated by If statement,but how can i delete the " and " at the end of the statement and make the remain to be a new String instance.
    thanks

    String trimmedStr = str.substring(0,str.lastIndexOf(" and "));

  • Unable to make a new instance of a class?

    Why can't I make a new instance of this object?
    This doesn't work:
            static void generateConfirmationDialog(String s1, String s2,
                String s3)
                int optionConfirmation = JOptionPane.showConfirmDialog(null,
                    "Confirm inputs: \n" +
                    "\n1: " + s1 +
                    "\n2: " + s2 +
                    "\n3: " + s3,
                    "Input Confirmation",
                    JOptionPane.YES_NO_OPTION,
                    JOptionPane.QUESTION_MESSAGE);
                if (optionConfirmation == JOptionPane.YES_OPTION)
                    //A new instance of an object.
                    //Class UserInterface
                    //Inner Class FileChooser
                    UserInterface.FileChooser fc = new
                        UserInterface.FileChooser.FileChooser();
                else if (optionConfirmation == JOptionPane.NO_OPTION)
                    //Returns the user to the main menu, with inputs intact.
            }Here's that class:
        public class FileChooser extends JFrame
            FileChooser()
                JFileChooser filechooser = new JFileChooser();
                int returnValue = filechooser.showDialog(this, "Upload");
                //Not done yet, but it should be able to display it
        }But this works:
        public static void main(String args[])
            UserInterface menu = new UserInterface();
        }

    1. Does class FileChooser need direct access to any nonstatic member variables or methods in the enclosing class (by your claim UserInterface)?
    If not, then just make the nested class static by:public static class FileChooser extends JFrame
        // body
    }note the static qualifier in the class definition. People frequently make inner classes where static nested classes would do equally as well or even better. Only if the nested class is "attached" to the instance is it necessary to make it non-static.
    2. If so, does the generateConfirmationDialog() have to be static?
    If not, simply remove the static qualifier from the method.
    3. If so, you will have to pass the instance created in your main() method to the method and use it to instantiate the inner class. The syntax isUserInterface menu = new UserInterface();
    FileChooser fc = menu.new FileChooser();4. Is there some reason you can't just use a filechooser from Swing?

  • How to parse a record (from record store) to String?

    Hi,
    I have a record store which stores movie titles specified by users (from multiple-selection list). I tried to access the records using nextRecord() from RecordEnumeration. This would return a byte array.
    How shall I parse the byte array to a String? I tried ByteArrayInputStream toString() method; I tried creating a new String with the byte as parameter. But it simply does not produce the original String. Sometimes it gives me something like a hex. string. Can anyone point out what has gone wrong?
    Thanks.

    lily2007 wrote:
    toString() returns this: "java.io.ByteArrayInputStream@1cb37664"
    What does it mean?That means that toString() is not overridden and does not return the content of the stream as a bytearray (ByteArrayOutputStream however does do this).
    I tried the new String(byte) method and got back the original String but with some whitespace in front.Let me guess: you write the string using writeUTF()?

  • Make a new window repeat the image?

    I have an image that I want to tile seamlessly. So I do the offset-thing and clone it. What I want to do now is to open a new window with the same image (Window > Arrange > New Window) for filename.ext and then tile the windows (Arrange > Tile), but then also make the new window to repeat the image so that I can see the edits I make reflect in the repeated image so I can get rid of unwanted patterns. I hope I'm not too vague about my question! Thanks!

    antevante wrote:
    Thank you for your answers! I didn't quite get it to work the way I wanted though.
    Can I somehow get my left window to show my image in a non-tiled state so that I can edit it while my right window shows the same image but tiled and zoomed out and updates when I make the edits in my left window? It's a bit of a pain in the *** to edit my image, then copy it and pasting it in an array. Then going back and editing, array again. This is a hassle even with an action. There's maybe other texturing applications for this kind of workflow but I thought I was so close with the New Window-feature in PS
    For the updating part you can use smart objects. There is one time setup that is more involved but then you can use this as a template for any future work.
    I just did that myself and described the steps:
    Create a canvas with a size that will fit perfectly many squares for example 1000 x 1000 to fit 100 squares with the size 100 x 100.
    On a new layer at the top left corner create a 100 x 100 square with any color or image.
    Right click on the layer with the square in the layer's palette and choose Convert to Smart Object.
    Hold Alt and drag the layer on top of itself 9 times to have total of 10 copies of the layer.
    On the canvas, make sure there is no selection, and with the Move tool drag one of the overlapping squares snapping it to the top right of the canvas (this is easy if Snap to Document Bounds is checked in the View > Snap to menu).
    In the layers palette Shift click the first and last layers to select all layers with the square.
    Make sure the Move tool is selected and in its options at the top of the screen click the "Distribute Horizontal Centers" button (the third from the right side).
    While all layers are still selected in the layers's palette, press Ctrl + G to group them.
    Duplicate  and distribute the group vertically in the same way you duplicated the squares but using "Distribute Vertical Centers" button instead. However, Alt+ drag a group doesn't work on a document with nothing but a single group, and I had to duplicate the first group by right clicking on it and choosing Duplicate. Then you can Alt + drag and drop between Groups.
    If you whish, while all groups are selected press Ctrl + Shift + Group, to ungroup and then Ctrl + Group to have all squares organized in one group and that's  basically it with the initial setup.
    Now edit a tile and update the image.
    In the layer's palette, double click the icon of any of the smart layers with a square and this will open the square in its own window.
    Change, create or paste new image on the image of that window and when you Save this will update all tiles in the other window.
    Also in case you don't know, when you are editing the square of the smart layer, you can use Filters > Others > Offset with Horizontal and Vertical set to 50 pixels and for the Undefined Areas, check Wrap Around. to help you with creating a seamless tile. It creates seamless borders and all you have to do is eliminate the seams in the middle with the cloning or painting tools.

  • ToString() and new String(),which is the better?

    now,there is very big StringBuffer sb,i want convert it to String s,which is the better:
    s=sb.toString();
    s=new String(sb);
    Thanks.

    now,there is very big StringBuffer sb,i want convert
    it to String s,which is the better:
    s=sb.toString();
    s=new String(sb);
    Thanks.this is the implementation advice for
    toString(StringBuffer)
    This method can be coded so as to create a new String object
    without allocating new memory to hold a copy of the character sequence. Instead, the string
    can share the memory used by the string buffer. Any subsequent operation that alters the
    content or capacity of the string buffer must then make a copy of the internal buffer at that
    time. This strategy is effective for reducing the amount of memory allocated by a string
    concatenation operation when it is implemented using a string buffer.
    so decide urself
    regards
    robert

  • ICloud is putting my mom's contacts on my phone since we have the same apple id. Should I make a new apple id just for Icloud?

    I want to be able to update all my stuff to icloud, but I don't want my mom's stuff constantly syncing with my phone too. If i make a new account, will that change what account i use in itunes and the apple store?? would I be able to have two accounts? or can you have two different users per icloud?
    because what are they supposed to do if a family shares an apple id?

    We upgraded my Mom's iPhone 3Gs (New Bootroom) to iOS 5 and connected My dad's Apple iD to my Mom's iPhone. My Mom and Dad's contact lists merged. Then today, when my mom was at work. She started deleting my Dad's business contacts from her phone, thinking that it would just be deleted off her phone. But, they were deleted off of my Mom's iPhone 3gs. My dad's iPad 2, iPhone 4, Intel iMac and his Windows Work computer. My dad is very frustrated. I am wondering if there is any way to do the stuff below, Please help we lost 100 contacts that are very important business contacts.
    I am wanting to get the missing contacts back and then seperate the contacts list and then creating my mom another Apple id and add her contacts to her new apple ID and then have so my Dad's Apple iD has his iPad 2, iPhone 4, iMac and his Windows Work Computer and my mom's Apple iD have her iPhone 3Gs (New Bootroom) with both contacts lists seperated.

  • HT3965 How do i make a new device account for my iphone? It has synced to my ipod account

    I purchased an Iphone 5 today. I plugged it into my computer and i opened itunes. Itunes asked if i wanted to created a new device account or if i wanted to connect to another device account. By accident, I clicked on my ipod device account and now my iphone only has my ipod loadout screen (apps i have on my ipod, no contacts, photos that are on my ipod). Is there any way i can disconect from this device acount and make a new one so my iphone goes back to normal?

    Settings
    General
    Reset
    Erase all Content and Settings

  • I have a new pc, and when updating ipad software it will erase all apps etc, is there any way to stop this from happening and make my new laptop my ipads "home" pc???

    I have a new laptop, and have copied over my existing itunes libary, but when i connect my ipad, and go to update the software to the new version it warns me that it will wipe all my apps etc..... How can i stop this from happening and make my new laptop the "home" for my ipad??
    Any help gratefully received! :-)

    Macs use an application called Migration Assistant to copy material from the old Mac to the new one. The macs are connected together and each runs Migration Assistance and the user chooses what stuf to copy onto the new Mac.
    Unfortunately I do not know how to do this between pcs or between a Mac and a Pf or even if it's even possible.

  • All iWeb options are greyed-out, and can't make a new sites or pages.

    Hello,
    I am having a very annoying problem with iWeb. Every option is greyed-out! I can't make a new page or site, and it quits as soon as I close the iWeb window. It is version 1.1.2 I have tried installing useless updates for iWeb that did nothing, and I've tried to open iWeb from iPhoto by clicking the iWeb button, which also did nothing. I'm just about to give up on it.
    Can anybody please point me in the right direction or have a fix for this? All help will be appreciated!

    Hi ineedagoodalias,
    The answer to your problem isn't necessarily the simplest, but I'm 99% sure that it will work for you.
    You need to delete and reinstall iWeb. Not hard to do; you just need your installation DVD's that came with your machine.
    Drag the iWeb.app from your Applications folder to the trash. Spotlight for other elements of iWeb, and trash those as well. Empty the trash and restart your machine.
    On your recovery disks, as you move through the prompts, look for "Install bundled software". Customize the install to include only iWeb. After reinstalling iWeb you will be back to 1.0.1.
    Update the app to 1.1.1 directly from this link:
    http://www.apple.com/support/downloads/iweb111.html
    This will get you going, and you can update to 1.1.2 when you are sure everything is working properly. For other FAQ on iWeb, please see this link:
    http://web.mac.com/varkgirl/iWeb/iWebFAQ
    Be sure to let us know how it goes.
    Mark

Maybe you are looking for