FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


SQL - length of a number (number of digits)





carlospro7
I'm trying to get the length of a number (the number of characters, or the number of digits plus the 1 period in a float number). The field that I'm using is of floats and when I use

Code:

SELECT field1, LEN(field1) length

it returns the length but the most it goes is to 7. For example

field1      | length
----------------------
234.3       | 5
23          | 2
4333.1      | 6
44.31543    | 7           (this one should say 8)
1.00000002  | 7           (this one should say 10)
3333.123433 | 7           (this one should say 11)


field1 is a field of floats

When the number has more than 7 characters it doesn't count them.
I have also tried converting the floats to chars, but I get the same results. LEN(CONVERT(char(53),field)). I tried plugging different numbers in the char(), but nothing.

When I select whats in field1 I get the actual numbers, so I don't understand what's going on.

I also tried decimals instead of floats, but it includes the trailing zeros at the end depending on how many decimals i specify it to have. I don't want to use decimals though b/c the data in field1 may need to have different decimals places.

I tried DATALENGTH but that just returns 8 for every column regardless of how many digits field1 has.

I don't think any data is lost since when I select all rows in field1 (floats) the actual numbers are displayed. So if I insert the number 3333.123433 (which has 10 digits + period, length of 11) in field1, "3333.123433" is displayed after a selection and not "3333.12" which has has a length of 7.

Can someone explain whats going, or know a solution to this.

Thanks,
los
badai
convert it to string first
sonam
badai wrote:
convert it to string first


and then use strlen:
http://www.php.net/strlen

Sonam
Related topics
Fortran Tutorials(77)
subject javascript code please help
sql with phpmyadmin
pi has my phone number&birthday in it
AJAX tutorial [2nd part now updated]
PHP and MySQL questions
PHP and SQL Server
Hacked by someone sql Injection
Need Expert help in php-mysql
Calculating number of rows
list number of rows in a table
Points/Coins/FRIH$ FAQ
learning MySQL
What is the problem with this function
Reply to topic    Frihost Forum Index -> Scripting -> Others

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.