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 Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Issues with Type conversion

Status
Not open for further replies.

rk33

Programmer
Apr 17, 2006
12
US
Hi,
I have a text field in an MS ACCESS table which contains a decimal number.
How can the number be converted from decimal to integer.
Example
String = 10.54

Needs to be converted to 10 and can remain a string...
Please help asap
Thanks,

 
Hi!

NewString = Left(OldString, InStr(OldString, ".") - 1)

This will bring back anything to the left of the decimal. Note, if not all of the values contain a decimal you will need to check for it first:

DecimalPlace = InStr(OldString, ".")

If DecimalPlace <> 0 Then
NewString = Left(OldString, DecimalPlace - 1)
Else
NewString = OldString
End If

DecimalPlace needs to be a long integer.

hth


Jeff Bridgham
Purdue University
Graduate School
Data Analyst
 
jebry's solution is appropriate if the current value is in fact a string. If it's already a numeric value and you simply want to truncate (not round) the fractional part then
Code:
IntegerValue = Int(TheNumber)

and if it's a string
Code:
IntegerValue = Int(Val(TheNumber))


[small]No! No! You're not thinking ... you're only being logical.
- Neils Bohr[/small]
 
Hi,
Thanks for your response.
I am writring this as a query in Business Objects..
can u suggest i can take care of the numbers which dont have decimal in my query?
coz it is giving me a error in Row 9 which is the error on any whole numbers
1 ,2 ,3
Thanks again!
 
Hi!

Since you are doing this in a query you can use:

Select IIf(InStr([Your Field], ".") = 0, [Your Field], Left([Your Field], InStr([Your Field], ".") - 1)) As WhateverNameYouWant

This is good if you are working in SQL, if your are using the query interface then you can put the following in the Field box:

WhateverNameYouWant: IIf(InStr([Your Field], ".") = 0, [Your Field], Left([Your Field], InStr([Your Field], ".") - 1))

hth


Jeff Bridgham
Purdue University
Graduate School
Data Analyst
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top