Parsing localized numbers

I'm trying to use NumberFormat to validate a string containing a formatted number but having a lot of problems. First, invalid strings are just ignored (same thing as http://forum.java.sun.com/thread.jsp?forum=31&thread=157703)
Also in French, space is used as thousands separators, however if I use a string with space only only the thousands are parsed, i.e.:
String value = "1 234,45";
try {
   Number number = NumberFormat.getNumberInstance(Locale.FRENCH).parse(value);
System.out.println(number.floatValue());
} catch (ParseException e) {
   e.printStackTrace();
}The output:
1.0
Any help? Thanks!

With the NumberFormat, you will get an exception only if the very first character is not parseable. But you don't have to write your own parse routine, just do this:
import java.text.*;
import java.util.*;
public class number {
   public static void main(String[] args) {
      try {
         DecimalFormatSymbols df = new DecimalFormatSymbols(Locale.FRENCH);
         df.setDecimalSeparator(',');
         df.setGroupingSeparator(' ');
         DecimalFormat NF=new DecimalFormat("#,###.##",df);
         String out=NF.format(-1234.56);
         System.out.println(out);
         ParsePosition PP=new ParsePosition(0);
         Number number = NF.parse(args[0],PP);
         if (PP.getIndex()!=args[0].length()) System.out.println("Parse Exception");
         System.out.println(number);
      } catch (Throwable exception) {
         exception.printStackTrace();
}V.V.

Similar Messages

  • Parse local HTML files

    Hi,
    I want to parse local HTML files.
    Is there another way than using the Internet Explorer($ie = new-object -com "InternetExplorer.Application";) (without relaying on external packages)?
    At the moment I do something like that:
    $ie = new-object -com "InternetExplorer.Application";
    Start-Sleep -Seconds 1
    $ie.Navigate($srcFile)
    Start-Sleep -Seconds 1
    $ParsedHtml = $ie.Document
    foreach($child in $ParsedHtml.body.getElementsByTagName('table'))
    I still want to have the methods like 'getElementById()' or 'getElementByTagName()'.
    With my current approache, the performance is not realy good and it seems that the iexplorer.exe process is not terminating at the end of the script. 
    Also it seems to have sideeffects with running internet explorer instances (from GUI) - not working to start IE in powershell sometimes.
    Last time I also have a hanging script, not continuing till i manually terminate the iexplorer.exe process.
    The error was:
    Exception calling "Navigate" with "1" argument(s): "The remote procedure call f
    ailed. (Exception from HRESULT: 0x800706BE)"
    At D:\Scripts\Run.ps1:529 char:14
    + $ie.Navigate <<<< ($src)
    + CategoryInfo : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : ComMethodTargetInvocation
    so I would prefere a method parsing HTML without IE.

    Hi John Mano,
    Please also try to Parse local HTML files with
    System.Xml.Linq, the script may be helpful for you:
    Using PowerShell to parse local HTML files  
    I hope this helps.                               
    XML?
    I thought HTML is not compatible with xml. 
    And as I don't know LINQ good ... 
    Ok, I'll give it a try. later.
    I can't answer the question about other ways to parse HTML, but to close your IE session you should do the following:
    $ie.Quit() # this terminates the IE process
    $ie = $null # this frees the COM object memory
    Thanks for that.
    I now use that, but seems to be still some IEs open ...
    Maybe a path missing where i dont do it.
    But finally I still get this error. And it is blocking the whole script ...
    Exception calling "Navigate" with "1" argument(s): "The remote procedure call f
    ailed. (Exception from HRESULT: 0x800706BE)"
    At E:\DailyBuild\Scripts\PublishTestResults.ps1:533 char:15
    + $ie.Navigate <<<< ($srcFile)
    + CategoryInfo : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : ComMethodTargetInvocation

  • I am currently in Cameroon, Africa and after arriving here, I added Global services to my plan in hopes to be able to use my phone to call local numbers.  When I dial local numbers in Cameroon, with or without the country code, the call fails.  I suspect

    I am currently in Cameroon, Africa and after arriving here, I added Global services to my plan in hopes to be able to use my phone to call local numbers.  When I dial local numbers in Cameroon, with or without the country code, the call fails.  I suspect it may be that the phone is 3G and this area only supports 2G.  Help!

    cctga,
    We appreciate you taking the time to reach out to us. I am sorry to hear that you are having trouble while traveling. We definitely want to make sure you have all available options. Normally when traveling internationally we reccommend setting up international services prior to leaving. When you added the services did you do so online or with a rep? It would be best to contact our global department in order to troubleshoot any and all issues with services while international http://vz.to/17KseUf.
    Thank you,
    TonyG_VZW
    Follow us on Twitter @VZWSupport

  • Videoconferencing through H323 Gateway works only to local numbers.

    Video is working to local numbers but not Interstate or International numbers. This has been working before for a long time and suddenly stopped working now.

    Whoops, I realize now that you have already posted all the necessary info.
    At first look the config appears correct. The router doesn't even try to switch out the call coming on BRI to PRI. But you say it does for national calls.
    Also strange, even before the call is placed, router reports "all channels taken on bri2/0". If that was true, the videodevice should not ever attempt a new connection! That looks like a classical case of ISDN data structure trashing in which the channel usage status as seen by the router is wrong.
    Can you take a trace with only "debug isdn q931" enable, to compare a successful call with one that doesn't work?
    All failing one could try upgrading to latest that is 12.4(11)T1 now.

  • Parsing Phone Numbers

    Hello,
    We are working on an integration that needs the phone numbers in CRMOD parsed out into the individual components. Currently the Web Services provide a phone number in it's full form. We would like to get the country code, area code, phone number, and extension as separate values. In CRMOD this is automatically done when you click on the "phone" icon. I'm not sure if CRMOD stores these values separately, or if this is just an algorithm. If it is an algorithm, has anyone re-created it?
    Thanks.
    Neal G.

    Check out the following template from metalink.
    Address Mapping Template and Phone Mapping Guide (Doc ID 556551.1)

  • Parse Localized Date String

    The javascript function util.printd has great support for localized date strings using XFAPicture.  However, util.scand doesn't appear to have the same support.  How would I go about parsing a date string that is in a localized form?
    Thanks in advance.

    Do you have your application language preference set for Spanish for Acrobat/Reader?
    Printing is done form the Date Object and not a string value.

  • Parse locale datestrings

    i'm not really a java programmer (coldfusion actually) but i need to fill in some i18n gaps with some java. dateformat, simpledateformat, etc. works a treat. however datestring parsing is killing me. parse() requires knowing the date/time format a datestring is formatted in. how can i determine the format a given datestring is in, especially when these strings might be coming in with localized full month or day of week names or some wild combo of LONG date, SHORT time, etc. any ideas?
    thanks.

    You should know the locale of the user then you can test the following four types of "style";
    int style= DateFormat.SHORT
    int style= DateFormat.MEDIUM
    int style= DateFormat.LONG
    int style= DateFormat.DEFAULT
    in the static method getDateInstance(int style, Locale aLocale)
    http://java.sun.com/j2se/1.4.1/docs/api/java/text/DateFormat.html#getDateInstance(int,%20java.util.Locale)
    and try applying the method parse(String)
    http://java.sun.com/j2se/1.4.1/docs/api/java/text/DateFormat.html#parse(java.lang.String)
    and catch the java.text.ParseException. If PerseException was not caught then the parse might have been successful.

  • Parsing long numbers as strings

    Hi
    Is there any way you can prevent a long number being converted to scientific notation? I have to write a method that substrs out each numeric character from a long positive whole number but when the number gets lon it falls over as the number is converted to scientific notation containing '.' and 'E' etc
    Any help would be appreciated
    Cheers

    Hi guys
    Thanks for the replies. I think the FM with 63 9s will probably be the simplest.
    I'm sorry I wasn't able to post an example as I was just heading out of the office for the day, but have got home so, for completeness will try to pen an example...although I don't have a server here so will be guessing syntax etc :-)
    Please forgive me if it doesn't run first time, but it should convey the intention...if necessary I'll debug it in the morning.
    Cheers
    declare
    mystring varchar2(1000) := '9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999';
    thisnum number;
    retnum number := 0;
    k number;
    begin
    k:=1;
    while k >0 loop
    for i in 1...length(mystring) loop
    thisnum != to_number(substr(mystring,i,1));
    retnum := retnum +thisnum;
    end loop;
    if length(retnum) > 60 then
    mystring := 'retnum';
    else
    k :=0;
    end if;
    end loop;
    --in the real case the retnum value would be stored at this point
    end;
    the 'while' loop if needed for very long strings where the 'addition' step hasn't decreased the length enough to be parsed as a number, the problem I have encountered only happens when the resulting number from the first run is long enough for an implicit conversion to scientific notation, this example may not be long enough to trigger it.

  • Phone adds a 1 before dialing local numbers

    All of my contacts include the area codes in their numbers, and my phone adds a 1 to them before dialing which prevents connection. Anyone know how to stop this? Thanks.

    Press the talk button > then the blackberry button > go to options > smart dailing > look for the option to dail 1 for national dailing and turn it off.

  • How to change localized numbers in iGrid V11.5

    Hi,
    we use MII Version 11.5SR4 and I have a client which use a german localization on his PC.
    When the user call an irpt page with an iGrid then this iGrid is displaying numbers for this german client allways with a comma for a decimal delimiter like this example 3,14159 (Pi).
    I need to change this iGrid to display allways a dot and ignores the client settings for the decimal delimiter like this 3.14159.
    The MII documentation has here something for localization but I did not find a solution which allows me to change this.
    I tried with the NumberFormat Parameter e.g. <param name="NumberFormat" value="###.00" />,
    but the result is allways the same for the german client, it displays the comma instead of the dot.
    FYI: When I change the regional settings (Windows XP) for this client to english / us then it works as expected.
    I hope there exists an parameter or way to initialize this applet to work allways as an english/us applet. e.g. like: this
    <param name="Language" value="en" />
    To change the query to display a customized string is not an option, because there is too much to change in the background.

    Hi,
    Call the query which is giving this kind of result in BLS transction.
    And use this column values with available function and modify with your requirement.
    Use this method :
    stringreplace( String , search, replace )     ex:("3,14159", ",", ".")
    Use Doc and Row action block to get the desired output and use Xacute query in your irpt page.
    Hope this helps you.
    -Suresh
    Edited by: Suresh Hiremath on Jul 4, 2009 9:20 AM

  • Parsing out numbers

    Trying to parse out the number strings into its own columns with this expression:
    WITH T as
    (SELECT  '53-2010-2-101' test_string FROM DUAL union all
    SELECT  '2219-2010-3-22' FROM DUAL union all
    SELECT  '236350-2010-4-3' FROM DUAL)
    SELECT SUBSTR(test_string,INSTR(test_string,'-')-2) stu_id,   --This is incorrect
    SUBSTR(test_string,INSTR(test_string,'-',1,1)+1,4) fiscal_yr, 
    SUBSTR(test_string,INSTR(test_string,'-',1,2)+1,1) sess,      
    SUBSTR(test_string,INSTR(test_string,'-',1,3)+1,5) sch_id     
    FROM THaving problems with stu_id. How to count backwards with substr and instr? The results should look like so:
    STU_ID                         FISCAL_YR                     SESS                                        SCH_ID
    53                             2010                           2                                           101
    2219                         2010                           3                                            22
    236350                         2010                           4                                             3Thanks

    Would it be something like this?
    WITH T as
    (SELECT  '53-2010-2-101' test_string FROM DUAL union all
    SELECT  '2219-2010-3-22' FROM DUAL union all
    SELECT  '236350-2010-4-3' FROM DUAL)
    -- end of sample data
    SELECT substr(test_string, 1, instr(test_string, '-') - 1) stu_id,
            substr(test_string, instr(test_string, '-', 1, 1) + 1, 4) fiscal_yr,
            substr(test_string,
                   instr(test_string, '-', 1, 2) + 1,
                   instr(test_string, '-', 1, 3) - instr(test_string, '-', 1, 2) - 1) sess,
            substr(test_string, instr(test_string, '-', 1, 3) + 1, 5) sch_id
       FROM tSample execution:
    SQL> WITH T as
      2  (SELECT  '53-2010-2-101' test_string FROM DUAL union all
      3   SELECT  '2219-2010-3-22' FROM DUAL union all
      4   SELECT  '236350-2010-4-3' FROM DUAL)
      5   -- end of sample data
      6   SELECT substr(test_string, 1, instr(test_string, '-') - 1) stu_id,
      7          substr(test_string, instr(test_string, '-', 1, 1) + 1, 4) fiscal_yr,
      8          substr(test_string,
      9                 instr(test_string, '-', 1, 2) + 1,
    10                 instr(test_string, '-', 1, 3) - instr(test_string, '-', 1, 2) - 1) sess,
    11          substr(test_string, instr(test_string, '-', 1, 3) + 1, 5) sch_id
    12     FROM t;
    STU_ID          FISCAL_YR SESS            SCH_ID
    53              2010      2               101
    2219            2010      3               22
    236350          2010      4               3
    SQL> With regular expressions would look something like this:
    WITH T as
    (SELECT  '53-2010-2-101' test_string FROM DUAL union all
    SELECT  '2219-2010-3-22' FROM DUAL union all
    SELECT  '236350-2010-4-3' FROM DUAL)
    SELECT regexp_substr(test_string, '\d+', 1, 1) stu_id,
            regexp_substr(test_string, '\d+', 1, 2) fiscal_yr,
            regexp_substr(test_string, '\d+', 1, 3) sess,
            regexp_substr(test_string, '\d+', 1, 4) sch_id
       FROM t;Edited by: fsitja on Jan 28, 2010 6:07 PM

  • Parsing long numbers very huge

    Hi all:
    How i can parse a long number like this:
    String variable="E898374636475837";
    long v=Long.parseLong(variable);
    This code throw:
    Exception in thread "main" java.lang.NumberFormatException: E898374636475837
    at java.lang.Long.parseLong(Long.java:310)
    at java.lang.Long.parseLong(Long.java:363)
    at q.main(q.java:6)
    Please help me, I nedd parse many DES keys entered by the user keyboard.
    Thanks.

    The long number is very huge.
    Long number can store only 2 to the power 64 's
    value.But not that huge.... The range of long is from -2^63 to 2^63-1. The value here is not in that range.
    You'll need the class java.math.BigInteger to represent that value and it also has parsing methods of it's own; check the docs.

  • Parsing Double numbers

    I am trying to write a program for some maths coursework,and I am having problems compiling it on my laptop,but I can compile it on the university unix machines!
    Specifically,the line of code that appears to be causing the trouble is the following line of code :-
    double number = Double.parseDouble(stdin.readLine());
    When ever I try and compile the program on my laptop (it's running Windows by the way),i get an error message,saying that it cannot resolve symbol,with the ^ pointing to the full stop,ie between "Double" and "parse".
    Any help in rectifying this problem would be greatly appreciated.
    Thanks very much.

    to compile my code I am just using the command javac
    through the comman line?
    I really cant undestand the problem!Well, unfortunately javac doesn't have a -version option (at least prior to the 1.5 / 5.0 version). But I heard that the newest version does. What does javac -version display? If it doesn't show a version number but instead says something like "invalid flag: -version", then I'd guess that the version of that tool is old. Did you really install the JDK and not just JRE? Or maybe you goofed up an installation and ended up with an old javac tool in your PATH ahead of the version that you want.

  • How can I call local numbers using Siri in Azerbaijan?

    I am using Iphone 4S with the latest software version, and am trying to dial Azeri phone number in international format , Siri answers calling "phone number" then immediately answers sorry i cant call "phone number".

    You must add following attributes to APPLET tag(mayscript, scriptable):
         <applet
         codebase = "."
         code = "namingspart.Applet.class"
         width = "620"
         height = "500"
         hspace = "0"
         vspace = "0"
         align = "top"
         name="namingsPartApplet"
         id="namingsPartApplet"
         mayscript="true"
         scriptable="true">
         <param name="initLine" value="">
         </applet>
    ================================
    Sincerely,
    Melnikov V
    AlarIT programmer
    http://www.AlarIT.com
    ================================

  • Local to Long Distance Numbers ???

    I'm a commercial pilot and always on the road. All my local numbers do not have 1's in front of them, all my long distance numbers do. On my old phone i could select a number and then there was an option to add a 1 to the number. Is there a way to do this in the iphone without physically editing the number ? How does everyone else do it ?

    In the US it's not needed - AT&T automatically doers that for outgoing calls (i.e. you can dial 1-408-555-1212 or just 408-555-1212 and the call will go through just fine).

Maybe you are looking for

  • Error with SAP_PERIODIC_ORACLE_SNAPSHOT job in PI 7.1

    Gurus, I ma getting a dump in PI7.1 SPS 7 Oracle snapshot creation program aborted Error while copying from oracle view to SAP table Oracle view SAP$KCBFWAIT SAP table ORA_SAPKCBFWAIT Return code (ORA-....) 942 You tried to work with the name of a ta

  • IronPort ESA 170 Upgrade Failed

    Hi All, We have just got two IronPort ESA 170 appliances delivered. I started off with upgrading the firmware from version 7.5.2-101 to 7.6.3-019. One of the appliances got upgraded fine. However, I am getting an error on the other one. Exactly when

  • Migrate Oracle Rac 11.1.0.6 SE to Oracle Rac 11.2 EE

    Hi, is there some guideline to migrate e 11.1.0.6 RAC Standard Edition with ASM to a 11.2.0 RAC Enterprise Editon? Database is almost 800gb, index included. Some best practice? Some suggestion? Some links? Thanks in advance, Samuel Rabini

  • How to track role change

    We have several groups making changes to roles in our portal. Is there a way to track roles changes and where can I find this information. We have several plants and portal admins at each site making changes to "shared roles". I need to track these c

  • How to add Category Properties

    How do I find out what Category Properties are available for use in ValidIf elements when writing new Metrics? Looking at all the files I can see plenty of places where CategoryProperties are used, but I can not see where they are defined or where th