Use DecimalFormat on a global basis

Hi!
I have a problem with Scientific notations of doubles. (i don't want them to become scientific when writing into Strings)
I know I can use DecimalFormat to change the output-format, but as far as I have seen the only way to do this is to add some code whenever I want to write the number into the string.
Instead of writing
String s = "bla bla"+double.toString();
i have to write
DecimalFormat f;
f.setOptions/format etc ...
String s = "bla bla"+f.format(doublevalue);
My question is if it is possible to change the formatting in some kind of global way? ie so that I can keep the first way of writing but still make use of a custom formating of the value whenever it is written to a string.
For example
DecimalFormat f = (DecimalFormat) NumberFormat.getInstance()
f.setOptions/format etc
String s = "bla bla"+doublevalue.toString(); /which would produce a non-scientific representation of the double
Best regards
Daniel

What you are having a problem with is the behavior of the Double.toString() method; so, ideally what you want to do is override this method. Unfortunately for your issue, Double is final and cannot be overridden.
You could write a static method in a utility class that does what you want and would not take much more effort than calling toString().
Something like:
String s = "bla bla" + MyUtility.formatNumber(someDouble);Or you could just keep a reference to a single DecimalFormat instance that you call format on as needed.

Similar Messages

  • I have an airport extreme and express, if I use the extreme as a base station connected to my old router can I use the express to extend the signal while also creating a new network that only I can use?

    I have an airport extreme and express, if I use the extreme as a base station connected to my old router can I use the express to extend the signal while also creating a new network that only I can use? Essentially having two wifi connection off the same network? If so how do I set this up?

    Extending using a wireless connection always results in a performance compromise.
    If the Express is going to extend using a wireless connection, then the Express will need to be located about half way between the AirPort Extreme and the general area where you need more wireless coverage. The more that you have line-of-sight between the Extreme and Express, the better the network will operate.
    Remember......the Express can only "extend" the quality and signal speed that it receives, so it needs to be located where it can get a very good signal from the Extreme. Although Apple cleverly uses the term "extend", a more accurate term for the Express would be "repeater".
    If the Express will extend by connecting to the Extreme using a permanent, wired Ethernet cable connection......highly recommended for best performance.....then the Express can be located exactly where you need more wireless coverage. There is no signal loss at all through the Ethernet cable, so the Express gets a full speed signal no matter where it might be located.
    Post back to let us know which way to you want to go.

  • I bought my iPhone 4 open line in Vancouver, Canada last week for use here in my home base in Bangkok, Thailand.  But when I tried using my Thai sim, I get a very weak signal, if not a weak signal, then a no service status.  What do I do?

    I bought my iPhone 4 open line in Vancouver, Canada last week for use here in my home base in Bangkok, Thailand.  But when I tried using my Thai sim, I get a very weak signal, if not a weak signal, then a no service status.  I also have very weak wifi reception.  What do I do?
    I already tried the following:
    a. Turned the phone off and then on.
    b. Checked all wifi connections – no problem given that all our laptops and desktops can connect seamlessly.
    c. I tried restoring the phone to original factory settings via itunes
    d. Tried resetting the phone.
    e.     Tried different microsims from all networks
    f. However, all methods failed given that the network reception is very weak and often reflects – “no service”.  And with regards to the wifi reception It has difficulty in reading even the signal right in front of the wifi router.
    I went to two Apple resellers here in Bangkok and requested that they please look at my Iphone and have it serviced.  I was frustrated when they said that given that I bought my phone in Canada, they are not able to support me and should instead try to contact the Apple store in Canada. 
    I went to apple.ca website and went to the expresslane support and I was said to register and callback.  Tried calling the 1800 number but given that I was in Thailand I had difficulty getting a connection.

    1st sentence, 4th page of the iPhone warranty found here:
    Apple may restrict service to the country where Apple or its
    Authorized Distributors originally sold the hardware product.
    From the Repair terms and conditions found here:
    9. Availability of Service.
    Apple may restrict service to the country where Apple or its authorized distributors originally sold the
    hardware product, and to the countries listed in the table below. A list of authorized distributors is
    available online at:
    http://images.apple.com/legal/warranty/docs/iPhoneAuthorizedDistributors.pdf
    If you do not believe that, then see these search results which confirm my statement.

  • Creation of Material using BDC Session method & global class

    Hi
    Creation of Material using BDC Session method & global class by using oops.
    can anyone plz help me out

    Hi,
    it looks like it's not possible to call this BAPI wihtout material number. Here is a quote from BAPI documentation.
    When creating material master data, you must transfer the material
    number, the material type, and the industry sector to the method. You
    must also enter a material description and its language.
    Cheers

  • Is it possible to use an image as the "base" of a mapviewer?

    Hi,
    I am trying to use a jpg image as the "base" of a mapviewer. After Insert the image, I create a "georaster theme" for it. Then, I create a "base map" by using the georaster theme created in the previous step. Up till now, both "georaster theme" and "base map" can be preview normally. After that, I create a "title layer" by using the "base map" which I created. However, only a write rectangle shown up when I preview the "title layer".
    So, I wonder it is possible to make a map by using an image as it base? If yes, would you mind telling me how to make it done. And, what value should I input for the following parameter:
    a) When I import an image in mapbuilder:
    1) Top X coordinate , Top Y coordinate
    2) X resolution, Y resolution
    b) When I make a title layer:
    1) Max X , Min X, Max Y, Min Y
    2) Zoom in scale (Once I zoom in the image, the image is gone?? It's very strange)
    Here's the property of that image:
    Dimension = 288 * 175
    Width = 288 pixels
    Height = 175 pixels
    Horizontal resolution = 72 dpi
    Vertical resolution = 72 dpi

    iMacs late 2009 or newer can be used in Target display
    mode.  Any older, no can do.
    The only other way is via network Screen Sharing or
    some otherVPN network like solution.  The issue here
    though is that video performance will be pretty severely
    hampered.

  • Using Powermac G5 as a Base Station w/Airport Extreme Card...

    Hello. Can anyone tell me if I am able to install an Airport Extreme card into my Powermac G5 and use it as a virtual base station to share the internet and network with my Powerbook (which has an Airport card)?
    I have DSL going to my G5 via ethernet, and would like to share it wirelessly with my Powerbook. The cheapest way, if it works, would be to purchase an Airport Extreme card and install it into my G5. Any info is appreciated. Thanks!

    Yes it's possible:
    http://docs.info.apple.com/article.html?artnum=107484
    The down side is that the G5 has to be on for it to work and the setting doesn't stick between restarts or sleeping.

  • How to use abap memory in global class

    Hi experts,
                     I want to  know how to use abap memory in global class. when i try write export and import statement its showing
    error is export statement does not support in object oriented concept.
    Thanks
    Ramesh Manoharan

    Hi Ramesh,
    Export and import statements were not allowed to use in  classes. Create a global variable in public section of that class of type of  export parameter.Then pass value to the global variable of class  by calling that class.
    by
    Prasad GVK.

  • I just purchased an extreme.  I have an express.  The sales guy recommended setting up a hot spot with the express and use the extreme as a base station.  What does he mean and how do I do this?  What are the advantages?

    I just purchased an extreme.  I have an express.  The sales guy recommended setting up a hot spot with the express and use the extreme as a base station.  What does he mean and how do I do this?  What are the advantages?  How do I set this up?????

    I think he means to set up the main extreme as the main router or "main base station", and then use the express to "extend" the network.
    You can look up the manual for your express here for more details:
    http://support.apple.com/manuals/
    Extend the range of your network by adding AirPort Express to your existing AirPortExtreme or AirPort Express wireless network (this is called a Wireless DistributionSystem, or WDS). "
    Extending the Range of an Existing AirPort Extreme or
    AirPort Express Network
    You can extend the range of an existing AirPort Extreme or AirPort Express wirelessnetwork by setting it up in a WDS. Wireless computers can connect to the network andshare the Internet connection, share files, and play network games. If you connect yourAirPort Express to your home stereo, computers on your wireless network can useAirTunes to play music on the stereo from iTunes. If you connect a USB printer to yourAirPort Express, all of the computers on the network can print to it.
    n Open the AirPort Setup Assistant on a Macintosh, or the AirPort Express Assistant on acomputer using Windows XP. Follow the onscreen instructions to extend the range ofyour AirPort Extreme or AirPort Express network.
    Note: Extending the range of a network using WDS may reduce overall networkperformance.

  • Using RH to create Knowledge Base

    We are revamping the support area of our product website and we want to add a searchable knowledge base.
    As most of the information users want is already present in the help system, I'm considering expanding and slightly reorganising the help system and using that as the knowledge base rather than creating a new database with duplicate information.
    We would create a new entry point and have a number of FAQs and links that go directly to the relevant part of the help.
    Has anyone done this using RH and/or does anyone have any thoughts on this idea?
    And is it possible to search a compiled webhelp RH project from an external search box?
    Thanks

    Hi there
    As for the question of whether it's possible to search a compiled webhelp RH project from an external search box, I'm going to crawl out here on a limb and say it should be. After all, WebHelp (making an assumption here that you are using WebHelp) is nothing more than a collection of HTML pages all packaged together with a frameset and fancy coding that allows it to work as a unit. So if the search can crawl through typical web pages, it should be able to manage that.
    Cheers... Rick

  • How to display 2 decimal places using DecimalFormat?

    Hi, i would like to display an account balance from database using child.getAccountBal(). Before that, i want to use DecimalFormat to display 2 decimal places. I would like to know whether the codes below are correct. Can anybody guide me? Thanks.
    public static double roundTo2DecimalPlaces(double value){
              DecimalFormat df = new DecimalFormat("0.##");
              double d = df.format(value);
              System.out.println(d);
              return value;          
    And inside the jsp page...is that how i call the values?
    Account Balance: <%=roundTo2DecimalPlaces(child.getAccountBal())%>

    DecimalFormat's format method returns a String not a double,
    os you must return a String instead of a double.
    public String roundTo2DecimalPlaces(double value)
         DecimalFormat df = new DecimalFormat("0.00");
         String stringValue = df.format(value);
         return stringValue;
    <%= roundTo2DecimalPlaces(child.getAccountBal()) %>

  • Problem formatting a very big number (BigDecimal) using DecimalFormat

    Hi,
    I am facing an interesting problem here.
    Here is my code snippet:
    <code>
    java.math.BigDecimal dec = new java.math.BigDecimal("12345678901234567890");
    DecimalFormat df = new DecimalFormat("####################");
    StringBuffer strbuf = new StringBuffer();
    df.format(dec,strbuf,new FieldPosition(0));
    System.out.println("Formatted are :"+strbuf.toString());
    </code>
    The output printed is :
    Formatted are :12345678901234567000
    I also tried out:
    <code>
    java.math.BigDecimal dec = new java.math.BigDecimal("12345678901234567890");
    DecimalFormat df = new DecimalFormat("####################");
    System.out.println("Formatted are :"+df.format(dec));
    </code>
    The output printed is same as above.
    If i try
    <code>
    System.out.println("String is :"+dec.toString());
    </code>
    instead of using decimalFormat, the output is :
    String is :12345678901234567890
    But, i need to format this number in future and separate it using commas. I will use DecimalFormatSymbols. But, right now, this problem of the number getting rounded is my first concern.
    pls help.
    ...supriya.

    1. Look at the javadocs for DecimalFormt.
    2. "####################" is the same as "#" (and any other combination of # you can think of...)
    3. DecimalFormat will format a double or a long... if you need other numbers to be formatted you will have to develop your own or find a library that does it for you.

  • I am updating my airport express. However, the message comes up with Invalid value - advertising a service globally using Bonjour requires a global hostname. WHat does this mean?

    i am updating my airport express. However, the message comes up with Invalid value - advertising a service globally using Bonjour requires a global hostname. WHat does this mean?

    thank you thank you for taking an interest. this is so frustrating.
    i only have apple keyboard, mighty mouse, and 20 inch cinema display connected. this morning took out memory and tried to boot up with individual pairs in the first bank. first the (2)256, the (2) 1g, and then the other (2) 1g modules. everytime I get the weird fuzzy wheel under the logo after a while, black screen flashes, then grey apple logo fuzzy screen then black forever.
    I ran tiger updates this morn. still will only boot to safe mode. then tried to run leopard disk to install it
    will not boot from leopard disk.
    tried safe boot, then doulble click install leopard, restart, then the saga repeats with the pixely red square around the wheel.
    these are fresh drives with only what came on instll disk loaded.
    thanks again for taking an interest.
    i love this system(well at least i did). I want to install leopard on my powerbook too but am terrified to do so right now since it is working and I have work to do. Can't afford to have no computer to do my work on...self employment is great?!
    This is making me crazy. I anxiously await your words of wisdom.

  • How can i HALF_ROUND_UP using DecimalFormat and NumberFormat

    hi
    currently what i did is
    public static String formatNumber(double value){
            NumberFormat formatter = new DecimalFormat("#.00");
            return formatter.format(value);
        }1. 12.344 ==> 12.34
    2. 12.346 ==> 12.35
    3. 12.345 ==> 12.34
    But what i want for case number 3 is 12.345 ==> 12.35
    Because in oracle 12.345 it will always round up
    How do i do that using DecimalFormat and NumberFormat??
    Thanks

    As long as you're using Java 6, you can specify the rounding using
    setRoundingMode(RoundingMode roundingMode)
              Sets the RoundingMode used in this DecimalFormat.For the available modes - including "round half up" - see the Java 6 RoundingMode enum API.

  • About .56 using DecimalFormat class

    Hi,everyone,I want use DecimalFormat to format a number to String. I set the "###,###,###,###,###.00" to the format pattern of the class,then it will translate 12345.56 to 12,345.56,this is that I want. But the result of 0.56 is
    .56 not 0.56. How can I solve it?

    So appreciated for you wonderful solution!!!
    It works correctly.

  • Using built-in with global variables

    I am trying to setup built-in source code control for LabVIEW. It seems to be OK except in one case:
    Is it possible to use built-in with global variables ?
    VIs that use a global variable are supposed to be updated automatically when global variable is modified but what happen when VIs are checked-in ? LabVIEW cannot updated them. Is it necessary to check out all VIs before modifying global variable ? This is not convenient if global variable is used in more than 100 VIs !
    Is there another solution ? Can Perforce resolve this problem ?
    Thanks for your help !
    David

    You can still use and update global variables while they are checked in to SSC. The default values will still be saved in SSC but they can still be modified and read by other vi's.
    goldie

Maybe you are looking for

  • IPhone video recording is garbled!

    I'm not sure how or why but my iPhone 5 can no longer record video properly!! I just used it this week to capture some live performances and all the video is garbled and chunky and the audio was not working for most of it. The longest video was 7 min

  • Number of copies to print in ME21/22

    Hi all I'm searching where is specified the number of copies of purchase order to print in ME21/22 ... In my system (4.6C), I can see 4 as this number, but there's nothing in message determination (MN05). Where is specified this 4 ? Have you any idea

  • Document Printing/Exporting Offset

    Not too long ago I upgraded from CS 4 to 5.5.  I haven't done much printing until now.  I'm finding everything in InDesign that I print or export to PDF is offset by 1/8 inch to the left, leaving a wider margin on the right.  (As a PDF, this error be

  • Azure VM persistent page blob disks appear not to deliver 500 IOPs or 60 MB/s as expected

    I need to benchmark Azure standard A3 and A4 VMs to see if I can get the advertised 500 IOPs - 60 MB/s per disk. I'm aware of the 20k maximum IOPS per standard storage account. The following VM test is done in its own (standard) storage account. I te

  • 10.5 install problem;

    I downloaded and "installed 10.5 and mssg says installed, but itues remains 10.4.... any ideas?