Interesting problem comparing strings with integer values...

Jeff Hinrichs jlh at cox.net
Wed Jan 15 23:25:30 EST 2003


[...snip...]
> Programming is about solving problems.  I asked a programming question
> with a certain number of constraints as to what the solution could be.  I
do NOT
> think it's off topic for this newsgroup just because you don't like the
> constraints.  If you can't help me, that's okay.  But please don't flame
me.
>
> Chris.
The solution to your problem falls back to older language implementation of
similiar
constraints (ala COBOL/ISAM) you must define all numeric fields.
-0000000001.00000
+0000000000.00000
+0000000001.00000
All fields will have to be padded.  You can convert them to what ever format
when you present them
to the user but in the DB they must all be the same length, storing the
decimal isn't necessary but you will
have to define how many there are when you store and retrieve.  All numbers
must carry signs if negatives
are possible.  You won't be able to store arbitrary precision or size.  This
will allow you to index and
compare them the way that you want.  You convert with a function like

def cvtString2Float(dec=5,places=10, stringValue):
    # Here you whack away with stringValue[] to get sign, value right of
decimal, value left of and then cast and return
    return floatValue

going the other way:

def cvtFloat2String(dec=5,places=10,floatValue):
   # left as exercise for reader
  return stringValue

I've worked on junk like this before and if there was a better way I haven't
met a grey hair/beard that knew how.<g>
have fun!






More information about the Python-list mailing list