πŸš€ go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: borland.public.jbuilder.java.swing
7 messages
7 total messages Started by Lamjed Fri, 02 Jan 2004 15:38
decimal separator ',' or '.'
#1307
Author: Lamjed
Date: Fri, 02 Jan 2004 15:38
5 lines
952 bytes
Please ,
I have a problem to change the decimal separator from ',' to '.' in a
BigDecimal type .
Can you help me to do so
Thanks
Re: decimal separator ',' or '.'
#1308
Author: Serkan
Date: Fri, 02 Jan 2004 22:39
30 lines
2240 bytes
Hi
I am not sure if this is the thing you are asking but I also had a similar
problem while I was dealing with DecimalFormat. When I
format a number using decimal format it was formatted using the current
locale but when I tried to parse back the number as a number I
was getting a number format exception.
For ex:
if I format 1000000.2
    if thousands seperator is "." and decimal seperator is "," in the
current locale(eg: Turkish) formatted number becomes 1.000.000,2 and if I
try to parse this number back using Double.parseDouble it throws a
NumberFormatException

this is non-sense in my oponion. If a library uses the locale when
formatting it should use the same locale when parsing back. So I wrote my
own number format functions, and all I can suggests you is that.
I would also like to learn if there is another way that I don't know.
Thanks for all


"Lamjed" <antispam_lamjed@lineone.net> wrote in message
news:3ff59168@newsgroups.borland.com...
> Please ,
> I have a problem to change the decimal separator from ',' to '.' in a
> BigDecimal type .
> Can you help me to do so
> Thanks
>
>
>
Re: decimal separator ',' or '.'
#1311
Author: Lamjed
Date: Sat, 03 Jan 2004 08:26
45 lines
2465 bytes
hi,

can you send me this function (if it's possible)
thanks

lamjed
email : delete the (antispam_) antispam_lamjed@lineone.net


"Serkan" <serkan@insaat.org> a οΏ½crit dans le message news:
3ff5f035@newsgroups.borland.com...
> Hi
> I am not sure if this is the thing you are asking but I also had a similar
> problem while I was dealing with DecimalFormat. When I
> format a number using decimal format it was formatted using the current
> locale but when I tried to parse back the number as a number I
> was getting a number format exception.
> For ex:
> if I format 1000000.2
>     if thousands seperator is "." and decimal seperator is "," in the
> current locale(eg: Turkish) formatted number becomes 1.000.000,2 and if I
> try to parse this number back using Double.parseDouble it throws a
> NumberFormatException
>
> this is non-sense in my oponion. If a library uses the locale when
> formatting it should use the same locale when parsing back. So I wrote my
> own number format functions, and all I can suggests you is that.
> I would also like to learn if there is another way that I don't know.
> Thanks for all
>
>
> "Lamjed" <antispam_lamjed@lineone.net> wrote in message
> news:3ff59168@newsgroups.borland.com...
> > Please ,
> > I have a problem to change the decimal separator from ',' to '.' in a
> > BigDecimal type .
> > Can you help me to do so
> > Thanks
> >
> >
> >
>
>
>
>
Re: decimal separator ',' or '.'
#1314
Author: Serkan
Date: Sat, 03 Jan 2004 11:04
29 lines
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
Re: decimal separator ',' or '.'
#1316
Author: John McGrath [TeamB]
Date: Sat, 03 Jan 2004 14:07
27 lines
2054 bytes
On 1/2/2004 at 5:39:28 PM, Serkan wrote:

> When I format a number using decimal format it was formatted using 
> the current locale but when I tried to parse back the number as a
> number I was getting a number format exception.

You do not show the code or even say which methods you used.  It is
hard to tell what your problem is without that.

> this is non-sense in my oponion. If a library uses the locale when
> formatting it should use the same locale when parsing back. 

The Java libraries provide both locale-specific and locale-independent
formatting and parsing methods.  That makes a *lot* of sense, since
both are sometimes required.

It sounds like you are using a locale-specific method for formatting
and a locale-independent method for parsing.

-- 
Regards,

John McGrath [TeamB]

---------------------------------------------------
Before sending me e-mail, please read:
    http://www.JPMcGrath.net/newsgroups/e-mail.html
Re: decimal separator ',' or '.'
#1317
Author: Serkan
Date: Sat, 03 Jan 2004 18:41
24 lines
1983 bytes
Hi
> You do not show the code or even say which methods you used.  It is
> hard to tell what your problem is without that.

    I was using format method of a java.text.DecimalFormat object for
formatting and Double.parseDouble for parsing

> The Java libraries provide both locale-specific and locale-independent
> formatting and parsing methods.  That makes a *lot* of sense, since
> both are sometimes required.

    As I said that's my oponion, that's all. I had said " I would also like
to learn if there is another way that I don't know." in my first message,
and I still want to learn.


> It sounds like you are using a locale-specific method for formatting
> and a locale-independent method for parsing.

    I had to format the numbers formatted using the current locale to the
user and parse these numbers into doubles after the user modifies the data.

Regards
Serkan
Re: decimal separator ',' or '.'
#1318
Author: John McGrath [TeamB]
Date: Sat, 03 Jan 2004 23:56
24 lines
1812 bytes
On 1/3/2004 at 1:41:37 PM, Serkan wrote:

> I was using format method of a java.text.DecimalFormat object for
> formatting and Double.parseDouble for parsing

The format() method is locale-specific.
Double.parseDouble() is locale-independent.

> I had to format the numbers formatted using the current locale to
> the user and parse these numbers into doubles after the user modifies
> the data.

That sounds like you want the locale-specific methods in both cases.
For parsing, try using the parse() method from the same DecimalFormat
object that you use for formatting.

-- 
Regards,

John McGrath [TeamB]

---------------------------------------------------
Before sending me e-mail, please read:
    http://www.JPMcGrath.net/newsgroups/e-mail.html
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads