SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    PHP Otaku Gibb's Avatar
    Join Date
    Jul 2004
    Location
    Texas
    Posts
    454
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Inserting a decimal into a number

    I how this is an easy question. I have a database full of restaurants and hotels and such. These destinations have a latitude and longitude value associated with them in this format:
    Lat: 3305050
    Long: -9705050

    There are always 5 decimal places, but the leading number can have either 1 - 3 digits.

    I need to take the numbers and add a decimal at -5 spaces from the end. I was looking at substr to do this, but i'm not sure it would work for what i need.

    So basically, need:

    3305050 -> 33.05050
    -10205050 -> -102.05050

    TIA,

    Gibb

  2. #2
    SitePoint Wizard swdev's Avatar
    Join Date
    Oct 2004
    Location
    UK
    Posts
    1,053
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    try this code

    PHP Code:
     $lat 305050;
     
    $long = -9705050;
     
     
    $new_lat $lat 100000;
     
    $new_long $long 100000;
     
     echo 
    'ORIG#' $lat '# NEW~' number_format($new_lat5) . '~<br>';
     echo 
    'ORIG#' $long '# NEW~' number_format($new_long,5) . '~<br>'

  3. #3
    PHP Otaku Gibb's Avatar
    Join Date
    Jul 2004
    Location
    Texas
    Posts
    454
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    omg math, boy do i feel stupid


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
  •