10-07-2010, 08:01 PM
Just change "CLng()" to "CDbl()" It will work for both "123,123" and "123,123.21"
Although, I would argue that "123,123.21" is already formatted the way you want it, so running it through the above code is really unnecessary, but if you don't know the format at runtime, I guess this approach should be fine.
QTP Code Wrote:str_Value = "123,123.21"
If IsNumeric(str_Value) Then
___str_Value = FormatNumber(CDbl(str_Value), 2)
End If
MsgBox str_Value
Although, I would argue that "123,123.21" is already formatted the way you want it, so running it through the above code is really unnecessary, but if you don't know the format at runtime, I guess this approach should be fine.