1. recommendation

When writing/storing your data base records how is the best/your way of
dealing with numeric data. Do you save the records with the numbers
converted to strings and convert them back when read every time? Or do you
write them as numbers and on editText entry convert those to strings back
and forth from the file? I'm worried here about future ease of use in
reports and updates. On Theos Basic all this was handeled automatically
during I/O.

...george

new topic     » topic index » view message » categorize

2. Re: recommendation

Hi George,
my general rule is that if a value is going to be used in arithmetic
operations or numerical comparisions, then convert the text and store it as
a number. This is a *general* principle and there are always exceptions.

For example, if you are really concerned about the speed of conversions, you
might store the value as both text and as a number and use either as
appropriate at the time.

Another example. Consider street addresses. Normally you would store these
as text, but if your program had to sort addresses for some purpose, you
might consider storing the house number as a separate numeric field so that
"12 Main Street" would sort after "1 Main Street".

In my opinion, the Euphoria value() function is only suitable for very
simple or specific situations. It is not a general purpose text-to-number
conversion because it allows some malformed text to be converted and fails
on some correctly formed text.

  value("12 .10") ==> 12 (embedded space)
  value("1.2.3")  ==> 1.2 (too many dots)
  value("$12.10") ==> Fails, doesn't support currency symbols

  value("#AF") ==> 175
  value("#af") ==> Fails (only support upper case hex digits)
  value("#123") ==> 291 (always assumes '#' means hex number follows)

  value("1,210") ==> 1 (doesn't support thousand separator)

  value("1.210") ==> 1.21 (doesn't support European thousand separator)
  value("1,23") ==>1  (doesn't support European decimal separator)

  value("2d")  ==> 2
  value("2e")  ==> Fails (due to malformed "scientific" notation)
  value("2f")  ==> 2

  value("(1.23)") ==> Fails (doesn't support parenthesis for negative
numbers)

  value(" 1.23") ==> 1.23
  value("-1.23") ==> -1.23
  value("1.23-") ==> Fails (doesn't support trailing signs)

A number of alternate routines have been developed by contributors to the
Euphoria forum, so you might like to check them out before deciding to
always use value().

-----
Derek.

----- Original Message -----
From: "George Walters" <gwalters at sc.rr.com>
To: "EUforum" <EUforum at topica.com>
Sent: Thursday, August 30, 2001 2:55 AM
Subject: recommendation


>
> When writing/storing your data base records how is the best/your way of
> dealing with numeric data. Do you save the records with the numbers
> converted to strings and convert them back when read every time? Or do you
> write them as numbers and on editText entry convert those to strings back
> and forth from the file? I'm worried here about future ease of use in
> reports and updates. On Theos Basic all this was handeled automatically
> during I/O.
>
> ...george
>
>
>

new topic     » goto parent     » topic index » view message » categorize

3. Re: recommendation

thanks Derek. Interesting stuff...BTW were you able to unzip that file I
sent?

...george
----- Original Message -----
From: "Derek Parnell" <ddparnell at bigpond.com>
To: "EUforum" <EUforum at topica.com>
Subject: Re: recommendation


>
> Hi George,
> my general rule is that if a value is going to be used in arithmetic
> operations or numerical comparisions, then convert the text and store it
as
> a number. This is a *general* principle and there are always exceptions.
>
> For example, if you are really concerned about the speed of conversions,
you
> might store the value as both text and as a number and use either as
> appropriate at the time.
>
> Another example. Consider street addresses. Normally you would store these
> as text, but if your program had to sort addresses for some purpose, you
> might consider storing the house number as a separate numeric field so
that
> "12 Main Street" would sort after "1 Main Street".
>
> In my opinion, the Euphoria value() function is only suitable for very
> simple or specific situations. It is not a general purpose text-to-number
> conversion because it allows some malformed text to be converted and fails
> on some correctly formed text.
>
>   value("12 .10") ==> 12 (embedded space)
>   value("1.2.3")  ==> 1.2 (too many dots)
>   value("$12.10") ==> Fails, doesn't support currency symbols
>
>   value("#AF") ==> 175
>   value("#af") ==> Fails (only support upper case hex digits)
>   value("#123") ==> 291 (always assumes '#' means hex number follows)
>
>   value("1,210") ==> 1 (doesn't support thousand separator)
>
>   value("1.210") ==> 1.21 (doesn't support European thousand separator)
>   value("1,23") ==>1  (doesn't support European decimal separator)
>
>   value("2d")  ==> 2
>   value("2e")  ==> Fails (due to malformed "scientific" notation)
>   value("2f")  ==> 2
>
>   value("(1.23)") ==> Fails (doesn't support parenthesis for negative
> numbers)
>
>   value(" 1.23") ==> 1.23
>   value("-1.23") ==> -1.23
>   value("1.23-") ==> Fails (doesn't support trailing signs)
>
> A number of alternate routines have been developed by contributors to the
> Euphoria forum, so you might like to check them out before deciding to
> always use value().
>
> -----
> Derek.
>
> ----- Original Message -----
> From: "George Walters" <gwalters at sc.rr.com>
> To: "EUforum" <EUforum at topica.com>
> Sent: Thursday, August 30, 2001 2:55 AM
> Subject: recommendation
>
>
> > When writing/storing your data base records how is the best/your way of
> > dealing with numeric data. Do you save the records with the numbers
> > converted to strings and convert them back when read every time? Or do
you
> > write them as numbers and on editText entry convert those to strings
back
> > and forth from the file? I'm worried here about future ease of use in
> > reports and updates. On Theos Basic all this was handeled automatically
> > during I/O.
> >
> > ...george
> >
> >
>
>

new topic     » goto parent     » topic index » view message » categorize

4. Re: recommendation

It's funny you should mentions that. I recently added a couple routines to
the files I've been working on at Sourceforge to read/write "objects" in
files. They are stored in the file based on the type of atom or sequence,
and the number of bytes needed to store the data. I was hoping for some feed
back on those in particular. I used the following sequence to test it;

{1.006,{1,{2,{2.5,2.5},2},3},{1024,#FFFFFFF},"just some random text",-2.3,0}

It could write it to a file and reproduce it accurately as a useable object.
If you would  like to see it, I can either send it to you, or you can find
the files here;

http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/standardeu/esl/esl/

You will need file.e, pack.e, and error.e if you don't modify them. Feel
free to change the names of the files if you wish.

The files are NOT finished yet, but as I said, I was hoping for feedback on
the routines: get_object() and put_object(). I was trying myself to avoid
the "readable-string" conversions. There is no documentation on them as of
yet, so if you have any questions, please post them to the list.

Jason

----- Original Message -----
From: George Walters <gwalters at sc.rr.com>
To: EUforum <EUforum at topica.com>
Sent: Wednesday, August 29, 2001 9:55 AM
Subject: recommendation


>
> When writing/storing your data base records how is the best/your way of
> dealing with numeric data. Do you save the records with the numbers
> converted to strings and convert them back when read every time? Or do you
> write them as numbers and on editText entry convert those to strings back
> and forth from the file? I'm worried here about future ease of use in
> reports and updates. On Theos Basic all this was handeled automatically
> during I/O.
>
> ...george
>
>
>

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu