Which function returns the numbers represented in the string "$56.7"?
-
Abs
-
CDbl
-
Int
-
Val
To solve this question, you need to know about the different functions in programming that are used to convert strings into numbers.
A. Abs - This function returns the absolute value of a number. It doesn't convert a string to a number.
B. CDbl - This function in Visual Basic (and some other programming languages) converts a string to a Double data type, which is a type of floating point number. This would be able to convert the string "\$56.7" to the number 56.7.
C. Int - This function converts number a to an integer. It doesn't convert a string to a number.
D. Val - This function in Visual Basic (and some other programming languages) returns the numbers found in a string. It would also be able to convert the string "\$56.7" to the number 56.7, but it would stop at the first non-numeric character, so it wouldn't handle the dollar sign correctly.
So, the correct answer is:
B. CDbl
CDbl converts a string to a Double and, depending on locale/currency settings, can correctly parse strings containing a currency symbol like "\$56.7", returning 56.7. Val, by contrast, scans a string left-to-right and stops at the first character it doesn't recognize as part of a number — since $ isn't a valid numeric character, Val("\$56.7") actually returns 0, not 56.7. Abs returns absolute value of a number (not a string-parsing function) and Int truncates a number to an integer — neither converts a currency-formatted string into a number. So CDbl is the function that correctly extracts 56.7 from "\$56.7".