Implied decimal question

1. Member
Join Date
Dec 1969
Posts
80

## Implied decimal question

I am importing data that has an implied decimal point four spaces from the right. So 32.45 would look like 324500<BR><BR>Ho to I get 32.45 to assign it to a string?<BR><BR>I guess I could do... unitPrice = (price/100) ...but how do I get the decimal point in there?<BR><BR>Maybe... FormatNumber(unitPrice) --or-- FormatNumber(unitPrice,2)<BR><BR>And all together it would look like...<BR>unitPrice = FormatNumber(price/100,2)<BR><BR>Umm, did I just answer my own question?<BR><BR>======== TIME PASSES ========<BR><BR>Okay, I just tried doing<BR><BR>[code language="VBScript"]<BR>unitPrice = FormatNumber(rs("Price")/100,2)<BR>[/code]<BR><BR>But I get an error that says Type mismatch and the error is on that line. The Price datatype is ummm, well, in MS Access it says "Number" and the Field Size says "Decimal". I forgot what that translates into for SQL Server which is what I am using on the live server.<BR><BR>What can I do about this Type mismatch?<BR><BR>Thank you.

2. Senior Member
Join Date
Dec 1969
Posts
96,118

## A little lost...

YOu are saying that you are importing data where the numbers are actually *strings*??? So you get data such as <BR> "324500"<BR><BR>Or, I suppose, even if they are numbers it&#039;s the same thing. You get numbers that look like<BR> 324500<BR><BR>Why would you then divide them by 100??? My head--and my calculator--says that<BR> 324500 / 100 --&#062;&#062; 3245.00 (or 3245. if you are my calculator)<BR><BR>HUH?<BR><BR>Don&#039;t you mean that you want to do<BR> 324500 / 10000 --&#062;&#062; 32.4500 (or 32.45 if you are my calculator)<BR>????<BR><BR>Oh...and NUMBER values from Access *can not* be handled by all functions in VBScript. So your best choice is to do<BR> price = CDBL( RS("Price") ) / 10000<BR>and then, if you want to format it:<BR> FormatNumber( price, 2 )<BR><BR>But do *NOT* do<BR> unitPrice = FormatNumber( price, 2 )<BR>unless the *only* thing you will do with unitPrice is display it (e.g., via Response.Write).<BR><BR>Because the result of calling FormatNumber is a *STRING*! So if you tried to do<BR> unitPrice = unitPrice + 17<BR>you&#039;d probably end up with the string<BR> "32.4517"<BR>because it would just do concatenation.<BR><BR>

3. Member
Join Date
Dec 1969
Posts
80

## Oops, I meant 2 spaces

Whoops! They implied decimal is TWO spaces from the right. My bad.<BR><BR>Using CDBL worked great!<BR><BR>Thanks, Bill! :)

#### Posting Permissions

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