Page 1 of 1

how do i reduce a string length without losing meaning

Posted: Mon Jan 08, 2007 4:55 am
by Kadanis
hi

as part of an app i'm working on, a code is generated in the form number.number i.e. 5.9 (its not a decimal but a code), the problem is that this could be any 2 numbers for example 19972.198234, and this means the string length increases dramatically over time. What i'm looking for is a way that these numbers could be represented while still minimising the string length. The restriction is that what ever is done to them has to be reversable and the original 2 numbers retrieved.

Just wondered if anyone here had any suggestions/ideas on how i could do this, as i'm floundering a little

all suggestions welcome and i'll answer any questions you have that mind help understand the issue.

the app was written in a mixture of php4 and php5.

oh, the numbers can be encoded before they are put in the format x.y if that helps.

thanks

Posted: Mon Jan 08, 2007 5:14 am
by bokehman
Convert them to a higher base.

Posted: Mon Jan 08, 2007 5:45 am
by Kadanis
aha. and a little research on bases and i found the php function for it too ;)

thanks for the pointer

Posted: Mon Jan 08, 2007 6:10 am
by onion2k
I'd store the two numbers seperately in int fields in the database, and use CONCAT_WS to stick them together on queries.

Posted: Mon Jan 08, 2007 9:15 am
by feyd
Floating point has precision errors when you get out to certain ranges which can cause your numbers to become inaccurate. Stick with strings or just don't keep them together.

Posted: Mon Jan 08, 2007 3:03 pm
by kingconnections
What about explode and then using dechex -- Decimal to hexadecimal?

If there is always a . you could split on it and then store as a hex number.