How to parse a BigDecimal from a localized number String

I want to be able to build a BigDecimal instance from a localized String.
i.e.: From a string like "2.123,45123" I want to get when I get by doing: new BigDecimal("2123.45123");
The NumberFormat parse(String) method answers doubles, so I lose presition. When I do nf.parse(2,0000000000000000001) y get a Double representing 2. I can't make a BigDecimal from such a string afaik.
The problem is the localized version on the number (in the string) otherwise it works fine (with the US locale).

>>
So you only can't convert a string to a BigDoublethat
uses the ',' for the decimal place and the '.' forthe
real number separators? If that's the case, whycan't
you use a String buffer then to strip out all the
periods and replace the comma with a period so it
looks like a US decimal string then use that?Thank you very much for your answer. That would have
been a workaround. I found a BigDecimal parser that's
absolutely perfect for the task.
http://users.belgacombusiness.net/arci/math/
Gives to BigDecimals what java standard gives to all
the other Number subclasses. Good! Frankly, I'm usually just lazy enough to hack a solution.... because I like to say that I hack. evil laugh

Similar Messages

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

  • TS4268 How do I remove iMessage from my phone number?

    How do I remove iMessage from my phone number?

    Settings>>>Message>> Turn iMessage OFF

  • How to parse XML files from normal FTP Servers?

    I want to parse xml files from a normal FTP Servers , NOT the sap application severs itself. How can i do that?
    I know how to use the SAPFTP getting and putting files ,but I don't want to download and then parse it.
    Who knows how to parse it directly? I Just need to read the contents into a database.
    Thanks.

    I want to parse xml files from a normal FTP Servers , NOT the sap application severs itself. How can i do that?
    I know how to use the SAPFTP getting and putting files ,but I don't want to download and then parse it.
    Who knows how to parse it directly? I Just need to read the contents into a database.
    Thanks.

  • How can I send imessages from my phone number instead of my email?

    My phone reset and now my imessages only send from my email address instead of from my phone number. I tried settings> messages> send and receive and unchecked the email listed like i saw to try on previous questions, but instead of fixing my problem, it just made it so that now i cant send imessages whatsoever! How can i fix this? I just want to send imessages from my number instead of my email address!

    Hi gracem0324,
    Go to Settings>Messages>Send & Receive, and click on your Apple ID and sign out of Messages. Then sign on again. Sometimes it needs to reset itself....
    Cheers,
    GB

  • How do you store input from keyboard into a string array

    I am trying to learn java and one of the programs I am trying to write needs to be able to accept a machine hostname at the keyboard and stuff it into a string array element. I am sure I will be using something along the lines of:
    BufferedReader in = new BufferedReader(new InputStreamReader(
                             System.in));
                   String str = "";
                   System.out.print("Enter a FQDN to look up: ");
                   str = in.readLine();
    but how do I get the input stuffed into hostname[ ].
    Any hints or assistance will be appreciated.
    Michael

    Well part of. I need to be able to take a random number of hostnames (ie. mblack.mkblack.com, fred.mblack.com, joe.mblack.com, ...) and after the user presses the enter key between each entry, the inputted information is stored in an array element. for example with the three shown above the array would look like this after the user finished.
    hostname {"mblack.mblack.com","fred.mblack.com","joe.mblack.com"};
    the algorithm would be
    Prompt for hostname
    get user input and press enter
    store hostname into array element
    prompt for next hostname or enter with no input to complete entry and execute lookup.class methods.
    I have the program written and working fine if I use a static array where I put the hostnames in the list, but cannot figure out how to get the information from the keyboard to the array element.
    Thanks for the help though, the response is very much appreciated.
    Michael

  • How to block calls & texts from one telephone number

    How to block calls & texts from one telephone number

    Call number blocking is done only by the carrier. Some carriers allow users to input numbers to be blocked on a website.
    Verizon allows users to list up to five numbers to be blocked for free for 90 days by entering them in the users My Verizon site. I've found that 90 days has been sufficient to discourage most nuisance calls. But Verizon also provides a service ( for a fee) that will permanently block a number.
    So contact your carrier to see what they offer.

  • HT201300 How can I work out from the model number if a Macbook pro is a UK model?

    Is it possible to tell from the model number of a Macbook pro whether it is a UK model or not? The model number of the Macbook I'm interested in is MC975B/A.
    Thanks

    Neil, many thanks for your reply. if the number was MC975EA does that make it a Spanish model?
    acampb

  • How to get a BigDecimal from german number (12,34)?

    How can i convert a string "12,34" to a BigDecimal object (value of 12.34)?
    I tried using special locale NumberFormat, but this doesn't work:
         * Convert a string to a BigDecimal object.
         * @param string String to convert.
         * @param pattern Pattern format to parse input string.
         * @param locale Locale to use for text formatting.
         * @return BigDecimal BigDecimal object with value represented by <I>string</I>
         * or null if conversion failed or <I>string</I> is empty.
        public static BigDecimal toBigDecimal(String string, String pattern, Locale locale) {
            BigDecimal result = null;
            if (string != null) {
                if (pattern == null) {
                    pattern = "###,###,###,##0.####"; //default
                if (locale == null) {
                    locale = Locale.getDefault(); //default is GERMANY anyway ...
                DecimalFormat df = (DecimalFormat) NumberFormat.getInstance(locale);
                df.applyPattern(pattern);
                Number num = df.parse(string, new ParsePosition(0));
                if (num != null) {
                    try {
                        string = string.replace(',', '.');
                        result = new BigDecimal(string);
                    } catch (NumberFormatException nfe) { /* ignore */ }
            }//else: input unavailable
            return result;
        }//toBigDecimal()this code only works for string "12.34" but not for "12,34" (german style)... ?

    no, num.doubleValue() is not exact enough (can lead to different numbers after the decimal point). the only way i have found so far to convert exactly is to use the String constructor of BigDecimal.
    the starnge thing is, that the same value as a fixed string works, but not the string value:
        public static BigDecimal toBigDecimal(String string, String pattern) {
            BigDecimal result = null;
            if (string != null) {
                java.text.DecimalFormat df = new java.text.DecimalFormat(pattern);
                Number num = df.parse(string, new java.text.ParsePosition(0));
                if (num != null) {
                    try {
                        string = string.replace(',', '.');
                        System.out.println("1: "+new BigDecimal("12.34"));
                        System.out.println("2: "+new BigDecimal(string)); //thorws NumberFormatException, even though string has the value "12.34" (checked with debugger)
                        result = new BigDecimal(string);
                    } catch (NumberFormatException nfe) {
                        System.err.println("toBigDecimal():"+ nfe);
            return result;
        }//toBigDecimal()output:
    1: 12.34
    toBigDecimal():java.lang.NumberFormatException: 1234
    where is the decimal point? the debugger shows that 'string' has the value "12.34" (with decimal point)????

  • How can I delete messages from the local Sent folder without deleting from the remote server?

    I am running out of disk space on my local machine. Analysing this, I can see that a large amount of space is being taken up by local storage of Sent emails from my IMAP synchronised account.
    I do not see how I can delete the local copies from my PC without them being deleted from the Server as well. There is an account setting option under Synchronisation and Storage to delete messages, but it says they will be deleted from both the local machine and the remote server.
    I need to keep the server versions as these are business accounts and it is important I have all my old messages stored somewhere.

    Short answer: get a bigger hard disk.
    You could disable synchronization and free up the space on your local disk without loosing the messages. However, this would eliminate the possibility to create backups of your messages.<br>
    Since you mentioned this is important business mail, you shouldn't take chances.

  • How to parse/reformat data from catchall()'s ora:getFaultAsString()

    Hi,
    I would like to translate the ora:getFaultAsString() data that is available in a catchall() block into XML so it can be
    included in the Fault response message that I send back to the WS client in a client-friendly format.
    In other words, rather than returning the original fault data as an unstructured string element:
    com.oracle.bpel.client.BPELFault: faultName: {{http://schemas.oracle.com/bpel/extension}assertFailure} messageType: {{http://schemas.oracle.com/bpel/extension}RuntimeFaultMessage} parts: {{ summary=<summary xmlns:def="http://www.w3.org/2001/XMLSchema" xsi:type="def:string" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">Quote not found.</summary> ,detail=<detail xmlns:def="http://www.w3.org/2001/XMLSchema" xsi:type="def:string" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">No data found for quote id: 0 quote number: 1</detail> ,code=<code xmlns:def="http://www.w3.org/2001/XMLSchema" xsi:type="def:string" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">001</code>}
    I want to return the data available in that string in structured XML format within my response document. What I
    would like to generate from the above string is something like this:
    <faultAsString>
    <summary>Quote not found.</summary>
    <detail>No data found for quote id: 0 quote number: 1</detail>
    <code>001</code>
    </faultAsString>
    Is there a built-in way to do this? Not finding one myself, I tried using ora:parseEscapedXML(),
    but since ora:getFaultAsString() does not return pure XML, the parse function does not seem able to
    parse the string. I also was unsure of the XML object type that could be used to assign the returning
    object from parseEscapedXML() into if that is the correct approach.
    Any help is appreciated. Thanks!

    Here is the bpel I'm using in my catchAll() to try to manage the error string as described above. It does not work for me:
    <variable name="gRuntimeFault" messageType="bpelx:RuntimeFaultMessage"/>
    <assign name="AssignRutimeFaultMessage">
    <copy>
    <from expression="ora:parseEscapedXML(ora:getFaultAsString())"/>
    <to variable="gRuntimeFault"/>
    </copy>
    </assign>
    When I run my WS I get this error in response:
    <env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/"><env:Header/><env:Body><env:Fault><faultcode>env:Server</faultcode><faultstring>XPath expression failed to execute.
    An error occurs while processing the XPath expression; the expression is ora:parseEscapedXML(ora:getFaultAsString()).
    The XPath expression failed to execute; the reason was: Start of root element expected..
    Check the detailed root cause described in the exception message text and verify that the XPath query is correct.
    </faultstring><faultactor/><detail><exception/></detail></env:Fault></env:Body></env:Envelope>

  • How to parse the year from a date.

    Hi,
    I have the following date format in database.
    05-SEP-07
    18-OCT-07
    18-OCT-07
    25-JUL-07
    18-OCT-07
    What I am trying to do is get only the full year from the date, example
    2007
    2008
    2009
    I tried to use extract function but that doesn't work due to ORA-01843: not a valid month.
    Thanks in advance.
    select extract(year from date '18-OCT-07') from dual;

    OK. You got an error using date literal. Did you at least look in documentation on date literals? I guess not, otherwise you'd see that data literal synatx is DATE 'YYYY-MM-DD':
    SQL> select extract(year from date '18-OCT-07') from dual;
    select extract(year from date '18-OCT-07') from dual
    ERROR at line 1:
    ORA-01843: not a valid month
    SQL>
    SQL> select extract(year from date '2007-10-18') from dual;
    EXTRACT(YEARFROMDATE'2007-10-18')
                                 2007
    SQL> SY.
    P.S. "I have the following date format in database" is completely wrong dates are always stored in one format - internal date format that stores year, month, day, hour, minute and second. When you select date using client tools like SQL*Plus, SQL Developer, Toad, etc. date is converted to string using either explicit or implicit format where you specify which parts of date you want to see.

  • How to parse/extract XML from clob field using ODI

    Hi,
    I am very new to ODI. I have an oracle table which has clob field. This clob field contains xml. I would like to parse this xml and convert it to oracle table. Means I would like to make all the tags of xml as oracle table columns.
    I have created a PL/SQL procedure and used XMLTABLE function and I have achieved my goal. The same this I am trying to do with ODI. Since I am new to ODI so any help is appreciated.
    Thanks

    In 9.2, you are limited into your options. Have a look into, among others, updateXML. Updating tp 10gR2 will give you more options to succeed.

  • How I can disable Firefox from browsing Local drives of servers for remote desktop users in Windows Server 2008 R2 SP1??

    Hi ..
    Recently I came across a security hazard in firefox. it displays C and D rives content when "C:\" or "D:\" is typed in browser address bar. is there any workaround for restricting domain users to restrict this on firefox 12 ??
    Thanks

    Hiya,
    It could sound like that one indeed. There are a few options to go for, however it should be fairly easy to find out :)
    Create a test GPO and apply to a limited amount of users. GPUpdate and verify that the GPO has been applied using rsop.msc
    Then open the application to test and see if it has the desired effect. You might need to change more than one setting, depending on the application and desired behavior.

  • How to exclude last page from the total number of pages counter

    Hi,
    I am customizing the payables remittance RTF template, our requirement is to reset page number to 1 for each payment, i am able to achieve this using "@section"
    also we have a requirement to have a summary page at the end, i am able to get this using "start@last-page:body".
    issue is last page is also considered in the page counter of the last payment.
    i.e. suppose if i am generating remittance for 2 payments which are printing details in two pages and one page respectively, my output will have total 4 pages and it's showing
    Payment1 page-1 footer -> 1 of 2
    Payment1 page-2 footer -> 2 of 3
    Payment2 page-3 footer -> 1 of 2
    Summary page-4 footer -> 2 of 2
    but i wanted to see
    Payment1 page-1 footer -> 1 of 2
    Payment1 page-2 footer -> 2 of 3
    Payment2 page-3 footer -> 1 of 1
    Summary page-4 footer -> 1 of 1
    Any idea how to remove the summary page from the page counter.
    Rgds,
    -Kamal

    I'm not sure how it was in Acrobat 9, but in XI you add a Header/Footer and
    one of the options it "Page Number and Date Format", where you can select
    the format of the page number to add, some of them contain the total number
    of pages (such as "1 of n").

Maybe you are looking for