Data Type Identifier - Problem

Given a value, determine whether it is an integer, float, string, or boolean.

Your task is to analyze the input value and return the appropriate data type as a string. The function should be able to distinguish between:

  • "integer" - whole numbers like 42, -15, 0
  • "float" - decimal numbers like 3.14, -2.5, 0.0
  • "string" - text values like "hello", "123abc", ""
  • "boolean" - true or false values

Return the detected type as a lowercase string.

Input & Output

Example 1 — Integer Value
$ Input: value = "42"
Output: "integer"
💡 Note: The string "42" represents a whole number without decimal places, so it's classified as an integer.
Example 2 — Float Value
$ Input: value = "3.14"
Output: "float"
💡 Note: The string "3.14" contains a decimal point and represents a floating-point number.
Example 3 — Boolean Value
$ Input: value = "true"
Output: "boolean"
💡 Note: The string "true" is a boolean value (case-insensitive match).

Constraints

  • Input will be a string representation of a value
  • Boolean values are case-insensitive ("True", "FALSE", etc.)
  • Integer values can be positive or negative
  • Float values must contain a decimal point

Visualization

Tap to expand
INPUTALGORITHMRESULTValue:"3.14"String input needstype classification1Check Boolean"true" or "false"? ✗2Check IntegerParse as int? ✗3Check FloatParse as float? ✓4Return Type"float" detectedOutput:"float"Successfully identifieddecimal number typeKey Insight:Built-in parsing functions automatically handle edge cases and providereliable type detection without manual pattern matching.TutorialsPoint - Data Type Identifier | Built-in Type Checking
Asked in
Microsoft 25 Apple 18
12.0K Views
Medium Frequency
~8 min Avg. Time
450 Likes
Ln 1, Col 1
Smart Actions
💡 Explanation
AI Ready
💡 Suggestion Tab to accept Esc to dismiss
// Output will appear here after running code
Code Editor Closed
Click the red button to reopen