Integer Question
-
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
-
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
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
-
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
Might be a coding horror...but I did this private String TwoDigit(int x) { return x.ToString.PadLeft(2, "0"c); }
-
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
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 -
Might be a coding horror...but I did this private String TwoDigit(int x) { return x.ToString.PadLeft(2, "0"c); }
int.ToString ( "00" )