Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to convert numeric fields to character fields... 2

Status
Not open for further replies.

bgruver

MIS
Oct 30, 2000
14
US
I need to create a table in which I'm inserting decimal and integer fields into character defined fields. How can I figure out how big each character field should be?

An integer field is 4 bytes, correct? How many character spaces will be needed to hold the largest possible integer value?

The decimal field is what really confuses me. The precision of my decimal fields are (9,2) and (10,2). How many character fields are needed for each.

If someone could explain how to figure these things out in addition to doing the computations I'd be delighted!

Thanks in advance.
Brian
 
Ok Brian.

For integer fields:

There are 8 bits/byte, 4 bytes/integer so the largest number an integer can hold is (2**31)-1 or 2,147,483,647.
That is what it would be if every bit were on. A character field to hold an integer would need to be 11 (or 12 for signed integer) characters long.

Decimal's are actually easier than integers to figure out. The definition tells you how many total digits the number can contain. Decimal(9,2) tells me that the number will have a total of 9 digits and 2 of those will be to the right of the decimal point. So to define a character field to hold a decimal(9,2) it would need to be 10 characters long (9 characters for the digits and 1 for the decimal point).

I hope this helps.
Tony
 
Tony:
Thanks so much for the quick response!

I do have a question for you about the decimal. You stated that the (9,2) decimal would only need 10 spaces. Why wouldn't it be 12 spaces (9 digits + decimal point + 2 digits after decimal)?

Brian
 
Brian,

No, the 9 is the TOTAL number of digits. Maybe this will help. The format statement for a Decimal(9,2) would look like this: format'9,999,999.99'

There are 9 total digits, 7 before the decimal and 2 after. Does that make more sense?

Tony
 
Oh, I get it now. I misread your post. I obviously have been misunderstanding the definition of a decimal datatype! You learn something everyday!

Thanks Again!

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top