PRB: Error Converting String to Numeric Value When Using "%" (145695)



The information in this article applies to:

  • Microsoft Visual Basic Learning Edition for Windows 5.0
  • Microsoft Visual Basic Learning Edition for Windows 6.0
  • Microsoft Visual Basic Professional Edition for Windows 5.0
  • Microsoft Visual Basic Professional Edition for Windows 6.0
  • Microsoft Visual Basic Enterprise Edition for Windows 5.0
  • Microsoft Visual Basic Enterprise Edition for Windows 6.0
  • Microsoft Visual Basic Standard Edition for Windows 4.0
  • Microsoft Visual Basic Professional Edition for Windows 4.0
  • Microsoft Visual Basic Enterprise Edition for Windows 4.0
  • Microsoft Visual Basic for Applications 5.0

This article was previously published under Q145695

SYMPTOMS

When converting a string that represents a percentage with the percent (%) character, you receive the following error:
Run-time error '13':
Type Mismatch
You may receive this error using the CDbl, CSng, CCur, or CDec conversion functions.

MORE INFORMATION

Steps to Reproduce the Problem

  1. Start a new project in Visual Basic.
  2. In the Debug Window (or Immediate Window), type the following and press the ENTER key:

    ?CDbl("12.00%")

  3. You receive the run-time error "Type Mismatch".
  4. To correctly convert "12.00%" to a numeric representation, type the following in the Debug Window and press the ENTER key:

    ?CDbl(Format("12.00%", "0.00"))

  5. You should receive the results 0.12 as expected.

Modification Type:MajorLast Reviewed:5/7/2003
Keywords:kbprb KB145695