SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Hybrid View

  1. #1
    ********* Wizard silver trophy Cam's Avatar
    Join Date
    Aug 2002
    Location
    Burpengary, Australia
    Posts
    4,495
    Mentioned
    0 Post(s)
    Tagged
    1 Thread(s)

    Playing with more data types

    Hey,

    I'm trying to determine if the characters in a string really should be a float I have this code so far
    PHP Code:
    if ( strstr($val'.') && is_numeric(trim($val'.')) ) {
        
    settype($val'float');

    but it doesn't work. For testing, $val is '1.63'. It being changed to an integer with this code
    PHP Code:
    if ( is_numeric($val) ) {
        
    settype($valINT);

    and then I assume since that prunes out the decimal, it's not being picked up by the float checker.

    Any idea to fix this? I'm going to try putting the float checking code first and see if that makes a difference.

    Thanks

  2. #2
    SitePoint Wizard siteguru's Avatar
    Join Date
    Oct 2002
    Location
    Scotland
    Posts
    3,608
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    I'm going to try putting the float checking code first and see if that makes a difference.
    That's what I would have suggested. An alternative would be to count the number of dots in the value ...
    PHP Code:
    if ( is_numeric ($val) ) {
        if ( 
    substr_count ($val'.') == ) {
            
    settype ($val'float');
        } else {
            
    settype ($val'integer');
        }

    Ian Anderson
    www.siteguru.co.uk

  3. #3
    ********* Wizard silver trophy Cam's Avatar
    Join Date
    Aug 2002
    Location
    Burpengary, Australia
    Posts
    4,495
    Mentioned
    0 Post(s)
    Tagged
    1 Thread(s)
    IT WORKS!!!!!

    Thanks you so much


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •