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

Change 123.00 to 123 00 1

Status
Not open for further replies.

VOGEL24

Programmer
Jan 27, 2004
6
0
0
US
I found the following function (on this wonderful site)to work, But
Numbers like 123.00 and 123.50 convert To 123 and 123 5 with no zeros, and need to be like 123 00 and 123 50. as long as there are 2 numbers like 123.11 it works fine. Is there any way to force the zeros to apear? I cannot make the source field text because I have computations prior to converting the number. Any help would be greatly appreciated.
Mary


Public Function ReplaceString(ByVal SourceString As String, ByVal OriginalString As String, ByVal NewString As String) As String
'Recursive function ReplaceString searches Source string and replaces ALL OCCURRENCES of OriginalString with NewString.
'If a value for NewString is ommitted (or IsEmpty), then all occurrences of OriginalString are removed from the SourceString!

Dim Position As Integer

If SourceString = "" Or IsNull(SourceString) Then
ReplaceString = SourceString
Else
Position = InStr(1, SourceString, OriginalString)
If Position > 0 Then
ReplaceString = (Mid$(SourceString, 1, Position - 1) & NewString & ReplaceString(Mid(SourceString, Position + Len(OriginalString)), OriginalString, NewString))
Else
ReplaceString = SourceString
End If
End If
 
You don't say how you are calling the function but I assume it's something like
[blue][tt]
newString = ReplaceString ( myNumber, ".", " " )
[/tt][/blue]
If that's the case then try
[blue][tt]
newString = ReplaceString ( Format(myNumber,"0.00"), ".", " " )
[/tt][/blue]
 
Thanks it worked perfectly. I had tried the format but not in the same way. Thanks again.
Mary
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top