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

Add a decimal point to a number 3

Status
Not open for further replies.

nhidalgo

MIS
Jun 13, 2001
619
0
0
US
I am inputing the following from a text file
005476

I need to format it as 54.76
I have tried the format function with "0.00" as the format but it give me 5476.00 instead. Any help would be great.

Thanks

Nick
 
Lots of ways you could do it, but dividing by 100 would be the easiest.
 
Divide by 100 gets you the correct value, but you still need the format function, otherwise you get

5476 / 100 = 54.76
but
6300 / 100 = 63

so, you need

Code:
dim szValue as string
szValue = rs.fields(1) 'or wherever the data comes from
format(val(szValue)/100,"0.00")
 
sorry - the line beginning 'format' needs to put the value somewhere - like debug.print format...
or msgbox format...
 
Thanks guys, I just didn't think of dividing by 100. Thanks for the quick replies.

Nick
 
Just as an option:
If this is a fixed length field you could also do this:

x = Val(Format$("005476","@@@@\.@@"))

The Val() will change the returned value of the format function to a number in US fromat, and then change it from US format to the format for numbers as set in the region settings (concerning the decimal seperator)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top