Results 1 to 5 of 5

Thread: [resolved] odd str() behavior in Access2000

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    May 2005
    Posts
    530

    Resolved [resolved] odd str() behavior in Access2000

    Hello,
    I've noticed something odd about the str() function in Access2000. When I do a str(12345) or the like, the resulting string is " 12345". Note the space in front of the number. Does anyone know why that happens?
    Thanks.
    Last edited by rickford66; Aug 23rd, 2005 at 02:43 PM.

  2. #2
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: odd str() behavior in Access2000

    That is the nature of the Str function, the space is there as a "placeholder" for the + sign (if the number is negative, - will be shown instead of a space).

    If you want to convert a number to a string (without the space at the front) use CStr instead

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    May 2005
    Posts
    530

    Re: odd str() behavior in Access2000

    Thanks. I understand, but it seems silly. Why would I need a place holder? It seems that more often than not, I wouldn't. If I needed one, I could just put one in manually. Hmmm.

  4. #4
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: [resolved] odd str() behavior in Access2000

    It depends what you are doing with the number, if you are printing it in a column along with lots of other numbers (some of which are negative) then they will line up properly.

    Despite what most people think, Str is not designed for conversion, it is for formatting as I described. CStr is the function for converting to a string (just like CInt is for converting to Integer)

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    May 2005
    Posts
    530

    Re: [resolved] odd str() behavior in Access2000

    Ah yes. (showing my inexperience) Thanks.

Posting Permissions

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



Click Here to Expand Forum to Full Width