🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: borland.public.jbuilder.java.api
6 messages
6 total messages Started by RaynorPao Thu, 10 Apr 2003 16:08
int or float
#661
Author: RaynorPao
Date: Thu, 10 Apr 2003 16:08
6 lines
974 bytes
Hi all:

How can I determine a string is integer or floating?

Thanks.
RaynorPao.
Re: int or float
#662
Author: Kevin Dean
Date: Thu, 10 Apr 2003 18:06
27 lines
1783 bytes
If all you're looking for is a fractional part, then:

boolean isFloatingPoint = s.indexOf('.') != -1;

If you're worried about the size of the number and whether or not it will
fit into an int, that's another issue, but the above code should take care
of most cases.
--
Check out our latest white papers at
http://www.datadevelopment.com/papers/index.html

BladeNET Scores With Borland Enterprise Tools
Team Development with JBuilder and Borland Enterprise Server

Dolphin Data Development Ltd.
http://www.datadevelopment.com/

"RaynorPao" <RaynorPao.nospam@nospam.pchome.com.tw> wrote in message
news:3e959322@newsgroups.borland.com...
> Hi all:
>
> How can I determine a string is integer or floating?
>
> Thanks.
> RaynorPao.
>
>
Re: int or float
#663
Author: Tor Iver Wilhelmsen (TeamB)
Date: Fri, 11 Apr 2003 06:14
5 lines
1090 bytes
"RaynorPao" <RaynorPao.nospam@nospam.pchome.com.tw> writes:

> How can I determine a string is integer or floating?

Try Integer.parseInt() and catch any NumberFormatException thrown.
Re: int or float
#665
Author: RaynorPao
Date: Fri, 11 Apr 2003 14:06
24 lines
1599 bytes
Hi TorIver & Kevin:

Thanks for your reply.
I found a solution like this as below:

    try {
      Integer.parseInt(str);
      jTextField1.setText("int");
    }
    catch(NumberFormatException e1) {
      try {
        Float.parseFloat(str);
        jTextField1.setText("float");
      }
      catch(NumberFormatException e2) {
        jTextField1.setText("Not int or float");
      }
    }

But, I'm not sure it is OK or not.
Any suggestion, please?

Thanks.
RaynorPao.
Re: int or float
#666
Author: Gillmer J. Derge [TeamB]
Date: Fri, 11 Apr 2003 14:16
18 lines
1826 bytes
"RaynorPao" <RaynorPao.nospam@nospam.pchome.com.tw> wrote in message
news:3e96c819$1@newsgroups.borland.com...
> But, I'm not sure it is OK or not.

Looks OK to me.

You could also consider using java.text.NumberFormat.  The approach would
be similar.  Get a NumberFormat instance to parse integers and another to
parse floats.  Then try each one and catch exceptions to find the invalid
values.

The advantage is that it would be a little more robust to international
variations in number formatting.  For example, "1,234" means something very
different in the United States versus Germany.  In particular, it's a valid
integer in Germany but not in the U.S.

--
Gillmer J. Derge [TeamB]
Re: int or float
#667
Author: RaynorPao
Date: Sat, 12 Apr 2003 17:10
26 lines
1795 bytes
Hi Gillmer:

Thanks for your suggestion.
RaynorPao.

"Gillmer J. Derge [TeamB]" <spam@gillmerderge.com> ���g��l��
news:3e96ce20$1@newsgroups.borland.com...
>
> Looks OK to me.
>
> You could also consider using java.text.NumberFormat.  The approach would
> be similar.  Get a NumberFormat instance to parse integers and another to
> parse floats.  Then try each one and catch exceptions to find the invalid
> values.
>
> The advantage is that it would be a little more robust to international
> variations in number formatting.  For example, "1,234" means something
very
> different in the United States versus Germany.  In particular, it's a
valid
> integer in Germany but not in the U.S.
>
> --
> Gillmer J. Derge [TeamB]
>
>
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