Article View: borland.public.jbuilder.java.swing
Article #1314Re: decimal separator ',' or '.'
From: Serkan
Date: Sat, 03 Jan 2004 11:04
Date: Sat, 03 Jan 2004 11:04
29 lines
2125 bytes
2125 bytes
Hi again
Unfortunately I also don't have that function, I had written it for my
previous job. But it was not a complicated thing.
To parse the number; first replace thousands seperator with nothing then
replace decimal seperator with "." then parse the number.
I wrote a sample now
public void numberSample() {
String x=new String("1.000.000,2");
java.text.DecimalFormatSymbols sym=new
java.text.DecimalFormatSymbols();
System.out.println("Grouping
seperator="+sym.getGroupingSeparator());
/* if thousands seperator is "." then we must escape it by \ because it is a
special character for regular expressions, and \ is escape character in
strings and goes on :)
*/
String
re=(sym.getGroupingSeparator()=='.'?"\\":"")+sym.getGroupingSeparator();
x=x.replaceAll(re,"");
System.out.println("After grouping removed: "+x);
x=x.replace(sym.getDecimalSeparator(),'.');
System.out.println("Finally: "+x);
System.out.println("Double parsed:"+Double.parseDouble(x));
}
Hope this helps
Serkan
Technical Details
Message-ID:
<3ff69d76@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!newsfeed2.dallas1.level3.net!news.level3.com!zeus.visi.com!news-out.visi.com!petbe.visi.com!eusc.inter.net!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailReferences:
<3ff59168@newsgroups.borland.com> <3ff5f035@newsgroups.borland.com> <3ff67d83@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 111d45,c8a77c3c06d158b1 X-Google-Attributes: gid111d45,public X-Google-ArrivalTime: 2004-01-03 03:09:20 PST From: "Serkan" <serkan@insaat.org> Newsgroups: borland.public.jbuilder.java.swing References: <3ff59168@newsgroups.borland.com> <3ff5f035@newsgroups.borland.com> <3ff67d83@newsgroups.borland.com> Subject: Re: decimal separator ',' or '.' Date: Sat, 3 Jan 2004 13:04:05 +0200 Lines: 31 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2720.3000 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2727.1300 NNTP-Posting-Host: 195.174.146.35 Message-ID: <3ff69d76@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1073126774 195.174.146.35 (3 Jan 2004 02:46:14 -0700) Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!newsfeed2.dallas1.level3.net!news.level3.com!zeus.visi.com!news-out.visi.com!petbe.visi.com!eusc.inter.net!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail