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

Select all numbers after a decimal place

Status
Not open for further replies.

NewfieGolfer

Technical User
Mar 29, 2001
80
CA


I was hoping someone could suggest a function to select a number's decimal and all numbers after the decimal. Then cut and copy this to a text box on a form. The number is currently in a text box.

ex. Have:
text box 1 --> 3.778987665

Need to have:
text box 1 --> 3
text box 2 --> .778987665


Suggestions appreciated,

NG
 
NG:

If each value is just a single digit (never 10 or more) you can use the Left$ and Mid$ functions. If the values may exceed 9, you'll also need to use the InStr$ function.

Essentially, these functions allow you to select parts of any string or number.

Check out help for each and you should be on your way.

Good luck.
Larry De Laruelle
larry1de@yahoo.com

 
On the OnLostFocus Event of Text1, put the following code (change the field names accordingly):

=====
With Me
If Not IsNull(.Text1) Then
.Text2 = Left(.Text1, InStr(1, .Text1, ".") - 1)
.Text3 = Mid(.Text1, InStr(1, .Text1, "."))
End If
End With
===== Jim Lunde
compugeeks@hotmail.com
Custom Application Development
 
Why not treat it as a number?

=Int([NumberField]) <----- This gives you number to left of decimal
=[NumberField] - Int([NumberField]) <----- This gives you number to right of decimal
 


Thanks to all,

I forgot about the Int function. I never think of the obvious. Anyways, with a little manipulation for negetive numbers I got it to work. Thanks Again.


NG


 
Can anyone help?

I have a currency field called &quot;Amount&quot;. I would like to convert the decimal point in this field to a hyphen in a field called &quot;Amount1&quot;. My data is this £136.00 but I would like it to look like this 136-00. I am using a replace function with the following code:

Function Replace()

Dim Amount As Variant
Dim AmountLeft As String
Dim AmountRight As String
Dim Amount1 As Variant

Amount = Forms![FRM ChequeDetails]!Amount


AmountLeft = Left(Amount, InStr(Amount, &quot;.&quot;) - 1) & &quot;-&quot;
AmountRight = Mid(Amount, InStr(Amount, &quot;.&quot;) + 1)

Amount = AmountLeft & AmountRight

Forms![FRM ChequeDetails]!Amount1 = Amount

End Function

This is working fine except for data that has 00 after the decimal point. I have tried everything and am completely baffled. Can anyone help?

Regards

Kate

 
Not pretty, but it does work

Code:
Public Function basPounds(LbsIn As String) As String

    'Michael Red    7/2/02
    'Convert £136.00 to 136-00

    Dim Tmp As String
    Dim Idx As Integer
    Dim MyChr As String

    Idx = 1
    Do While Idx <= Len(LbsIn)
        MyChr = Mid(LbsIn, Idx, 1)

        Select Case MyChr

            Case &quot;0&quot; To &quot;9&quot;
                Tmp = Tmp & MyChr

            Case Is = &quot;.&quot;
                Tmp = Tmp & &quot;-&quot;

        End Select

        Idx = Idx + 1
    Loop

    basPounds = Tmp

End Function
[code] MichaelRed
m.red@att.net

There is never time to do it right but there is always time to do it over
 
Michael, no need to apoligize. Pretty is not everything, and it does work!

However, if one's hard-drive is filling-up and space is at a premium, we could try this from the debug window. It's essentially one (maybe two) line(s) of code:

Code:
widget = &quot;£136.97&quot;
widget = mid(widget, 2, instr(widget, &quot;.&quot;)-2) & &quot;-&quot; & mid(widget, instr(widget, &quot;.&quot;)+1)
? widget
136-97

HTH,

Bob
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top