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!

Truncate string with decimal point

Status
Not open for further replies.

Penrodcigar

Technical User
Aug 23, 2006
19
US
Anybody have a simple way to truncate a string number with a decimal so it limits the places after the decimal?
 
Something like this ?
Format(Val(yourNumericString), "0.00")

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
When I try your expression

Format(Val(yourNumericString), "0.00")

I get a Compile Error: Sytax error message

For "yourNumericString" I insert a variable for the string say TVar = "23.23567" so...Format(Val(TVar), "0.00")...is my expression

Not sure what to put for "Val"

and I presume "Format" is a CMD function
 
Code:
Public Function Tvar()
    Dim tvar As Double
    tvar = 23.23567
    tvar = Format(Val(tvar), "0.00")
    Debug.Print tvar
End Function
returns 23.24
What have you done differently?


Randy
 


Val function converts your number STRING to a NUMERIC VALUE.

Skip,
[sub]
[glasses] [red][/red]
[tongue][/sub]
 


...and

the Format function returns a STRING, which can, in turn, be converted to a NUMERIC VALUE.


Skip,
[sub]
[glasses] [red][/red]
[tongue][/sub]
 
That's great. Working fine now. Thank you....anybody have a convenient way to display decimals as fractions?

Regards,
Peter Landeck
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top