Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Integer Question

Integer Question

Scheduled Pinned Locked Moved C#
questiondatabase
5 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    jchigg2000
    wrote on last edited by
    #1

    Anyone know if it's possible to store integers that are < 10 in the 01, 02, 03 format? I have database fields that store hours and minutes in numeric format and I'd like to force the minutes field to be 2 characters in my object so when I display time I don't have to do some nasty if statement and string manipulation to get 1:01 not showing up as 1:1

    C J D 3 Replies Last reply
    0
    • J jchigg2000

      Anyone know if it's possible to store integers that are < 10 in the 01, 02, 03 format? I have database fields that store hours and minutes in numeric format and I'd like to force the minutes field to be 2 characters in my object so when I display time I don't have to do some nasty if statement and string manipulation to get 1:01 not showing up as 1:1

      C Offline
      C Offline
      Colin Angus Mackay
      wrote on last edited by
      #2

      jchigg2000 wrote:

      Anyone know if it's possible to store integers that are < 10 in the 01, 02, 03 format?

      If you do that then you are storing them as strings. Integers get stored as 32 bit values in binary.

      jchigg2000 wrote:

      I have database fields that store hours and minutes in numeric format and I'd like to force the minutes field to be 2 characters in my object so when I display time I don't have to do some nasty if statement and string manipulation to get 1:01 not showing up as 1:1

      Don't do that in the database it isn't designed for it. Databases are for storing information, not for the rendering of that information. Also, you also don't need "nasty if statements" you just have to learn how to use string.Format()

      Upcoming FREE developer events: * Developer Day Scotland Recent blog posts: * Mixins in C#3.0 My website | Blog

      1 Reply Last reply
      0
      • J jchigg2000

        Anyone know if it's possible to store integers that are < 10 in the 01, 02, 03 format? I have database fields that store hours and minutes in numeric format and I'd like to force the minutes field to be 2 characters in my object so when I display time I don't have to do some nasty if statement and string manipulation to get 1:01 not showing up as 1:1

        J Offline
        J Offline
        jchigg2000
        wrote on last edited by
        #3

        Might be a coding horror...but I did this private String TwoDigit(int x) { return x.ToString.PadLeft(2, "0"c); }

        P 1 Reply Last reply
        0
        • J jchigg2000

          Anyone know if it's possible to store integers that are < 10 in the 01, 02, 03 format? I have database fields that store hours and minutes in numeric format and I'd like to force the minutes field to be 2 characters in my object so when I display time I don't have to do some nasty if statement and string manipulation to get 1:01 not showing up as 1:1

          D Offline
          D Offline
          Dave Kreskowiak
          wrote on last edited by
          #4

          You don't store the rendered version of data in a database. You store the actual data. Displaying it in a ceratin format is up to your presentation code, not the database. Using numeric formats to do this is very easy:

          Console.WriteLine(String.Format("{0:00}:{1:00}", hours, minutes))
          

          A guide to posting questions on CodeProject[^]
          Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
               2006, 2007, 2008

          1 Reply Last reply
          0
          • J jchigg2000

            Might be a coding horror...but I did this private String TwoDigit(int x) { return x.ToString.PadLeft(2, "0"c); }

            P Offline
            P Offline
            PIEBALDconsult
            wrote on last edited by
            #5

            int.ToString ( "00" )

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups