Hi, I just wanna ask you some quick question: Why should I use string, integer or decimal? What's so good about them?
Printable View
Hi, I just wanna ask you some quick question: Why should I use string, integer or decimal? What's so good about them?
a variable stored as a String datatype will return any character as text
a variable stored as an integer datatype will return a number positive or negative as high as the bit used. default is 32 bit and returns a number from −2,147,483,648 to +2,147,483,647 signed and 0 to +4,294,967,295 unsigned.
Double is much like integer accept it allows the use of decimals.
"Double variables are stored as signed IEEE 64-bit (8-byte) double-precision floating-point numbers ranging in value from -1.79769313486231570E+308 through -4.94065645841246544E-324 for negative values and from 4.94065645841246544E-324 through 1.79769313486231570E+308 for positive values." -MSDN article on Double Datatypes.
Well, I'm currently working on a program which needs some bit of text to be outputted in a listbox. Also the program should do any calculations if needed. I have already declared variables for my textboxes and combo boxes to a string but I need a reason why it was the best choice. I have also used integers for counting several items - need reason why it was the best choice. As for the decimals, the program should do calculations for each item I choose from a combo box list or by simply checking the boxes - also need why decimal was the best choice.
If the data could contain non-numeric text (or numbers with extra leading 0's), you need to use a String - because numeric data types only hold numbers.
If the data is purely numeric then using the right data type saves memory, increases speed, and reduces the chances of errors. Which of the numeric data types you should use depends on the data (it is no good using Integer for numbers with decimal places, or Byte for numbers larger than 255).
Why do you wear pants, or shorts? Couldn't you just use a shirt as well? Would you use a hammer to put in a screw (properly I might add)? While the alternatives work, they are not the best tool for the job.
-tg
First, you wouldn't store text in a variable declared as an integer. Text is generally a string, so you'd use a string.
As for doing calculations, that's not relevant. You'd use a decimal variable to do calculations if there are decimals involved. You'd use integers if integers are involved, etc.
You can't store text in integers. They are strictly for whole numbers, however you can convert integers to text (strings).
Decimals can include decimals, which is good when you expect the result to be a non-whole number.
Mmokay... Thanks for your help guys, I can always count on you :)
Thread Resolved.