Skip to Content
VB.NET Language in a Nutshell, Second Edition
book

VB.NET Language in a Nutshell, Second Edition

by Steven Roman PhD, Ron Petrusha, Paul Lomax
April 2002
Intermediate to advanced
688 pages
19h 51m
English
O'Reilly Media, Inc.
Content preview from VB.NET Language in a Nutshell, Second Edition

Name

CDbl Function

Named Arguments

No

Syntax

CDbl(expression)
expression (required; Numeric or String)

-1.79769313486232E308 to -4.94065645841247E-324 for negative values, and 4.94065645841247E-324 to 1.79769313486232E308 for positive values

Return Value

expression cast as a Double data type

Description

Converts expression to a Double data type

Rules at a Glance

  • If the value of expression is outside the range of the double data type, an overflow error is generated.

  • expression must evaluate to a numeric value; otherwise, a type-mismatch error is generated.

Example

Dim dblMyNumber as Double
If IsNumeric(sMyNumber) then
    dblMyNumber = CDbl(sMyNumber)
End If

Programming Tips and Gotchas

  • When converting a string representation of a number to a numeric value, the data type conversion functions, such as CDbl, are preferable to the older function, Val. This is because the data type conversion functions take account of the system’s regional settings, whereas Val recognizes only the period as a decimal separator. For example, if a user inputs a value of 6,231,532.11, CDbl correctly converts it to a double with a value of 6231532.11, while Val returns a value of 6.

  • Use IsNumeric to test whether expression evaluates to a number.

  • Like most conversion functions, CDbl is not actually a function in the Microsoft. VisualBasic namespace. Instead, it is similar to a Visual C++ macro; the compiler translates the function call into inline code.

See Also

CSng Function

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

VB .NET Language in a Nutshell

VB .NET Language in a Nutshell

Steven Roman PhD, Ron Petrusha, Paul Lomax

Publisher Resources

ISBN: 0596003080Supplemental ContentCatalog PageErrata