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

convert string

Status
Not open for further replies.

makisbest

Technical User
Mar 3, 2005
125
GR
How I can convert a string like

"1234567"

to a number like

12345.67
 
If you're making it into .67 from the number then

strNum = "1234567"
x = Val(Left(strNum, Len(strNum) - 2) & "." & Right(strNum, 2))
-Max
 
Or to generalize shakespeare5677's excellent solution:

x = ConvertToNumber("1234567", 2)

Function ConvertToNumber(strNum, nDecDigits)
ConvertToNumber = Val(Left(strNum, Len(strNum) - nDecDigits) & "." & Right(strNum, nDecDigits))
End Function

[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 
Or

Public Function DecIt(strNumber, lDecPlaces) As Double
DecIt = strNumber / (10 ^ lDecPlaces)
End Function
 
Even better.

[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top