SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Enthusiast
    Join Date
    Jan 2014
    Posts
    56
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Round down to nearest 1000

    Hi guys

    I need to round down a value in my string <%=mileage%> to the nearest 1000. However, I need the output to only show a single digit:

    So,

    400 = 0
    800 = 0
    1200 = 1
    1800 = 1
    2000 = 2
    2400 = 2
    2600 = 2
    3000 = 3
    3500 = 3
    3985 = 3
    4544 = 4
    etc
    etc
    45000 = 45
    45600 = 45
    49200 = 49
    etc
    etc
    105000 = 105
    105400 = 105

    Is this at all possible? If so, how is it done?

    Any help would be fully appreciated

    Best regards

    Rod from the UK

  2. #2
    Avid Logophile silver trophy
    ParkinT's Avatar
    Join Date
    May 2006
    Location
    Central Florida
    Posts
    2,343
    Mentioned
    192 Post(s)
    Tagged
    4 Thread(s)
    I think all you need is

    Code:
    <%=mileage / 1000 %>
    Last edited by ParkinT; Jan 21, 2014 at 17:35.
    Don't be yourself. Be someone a little nicer. -Mignon McLaughlin, journalist and author (1913-1983)


    Git is for EVERYONE
    Literally, the best app for readers.
    Make Your P@ssw0rd Secure
    Leveraging SubDomains

  3. #3
    SitePoint Enthusiast
    Join Date
    Jan 2014
    Posts
    56
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks ParkingT

    Nearly. I just needed to divide by 1000 and then turn it into an integer (round)

    Thanks for your help

    Best regards

    Rod from the UK

  4. #4
    SitePoint Wizard siteguru's Avatar
    Join Date
    Oct 2002
    Location
    Scotland
    Posts
    3,631
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    What result does Round(800/1000) give?

    I'll save you checking - it is 1. So it doesn't give the result you stated you wanted (0). Int or Fix give you the correct answer.

    Code:
    <% =Round(800/1000) %>
    <% =Int(800/1000) %>
    <% =Fix(800/1000) %>
    Ian Anderson
    www.siteguru.co.uk

  5. #5
    SitePoint Enthusiast
    Join Date
    Jan 2014
    Posts
    56
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Excellent - thanks Ian

    Best regards

    Rod from the UK


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
  •