Re: recommendation

new topic     » goto parent     » topic index » view thread      » older message » newer message

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 thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu