Number Extractor



Number Extractor





Result Summary:

Type Result
Given Text 0
Extracted Numbers 0


What is Number Extractor?

Number extractor is a tool to extract any number (integer or float types) from a line of text. This tool takes a line or paragraph of text (which is of string type) and lists out all the numbers present in this text. It works with both integer and float numbers, as well as negative numbers. Consider the following example

Text: “For this recipe, we need 1.5 tablespoons of oil, 2 eggs, and 1 cup of milk.” The number extractor tool will return the following as output: 1.5, 2, 1

The number extractor tool is very useful if the text is really long. For example, if we were to find all the phone numbers and register numbers of fifty students in a class from a list containing their names, register numbers and phone numbers, this tool would promptly list out the phone numbers along with the corresponding register numbers.

If the text provided as input does not contain any numbers, this tool would display “No numbers found” or a similar error message.

Properties of Number Extractor

Given below are some important properties of the number extractor tool.

Input text – The line or block of text which is entered as an input to the tool. The text may contain only numbers, or no numbers at all, or be a mix of both numbers and letters. If the text does not contain any numbers at all, the number extractor would not be able to find any numbers.

This tool also does not recognize fractions. For example, the text “We need ½ cup of water for the plant” would result in “1, 2” which is incorrect. Instead, the text should read “We need 0.5 cup of water for the plant” for the output to be “0.5”. The number extractor tool does not recognize the ‘/’ in fractions.

Output numbers – The output obtained from a number extractor tool is always a number, be it an integer or a floating-point number. The tool also recognizes negative numbers. The lack of any numbers in the input text would result in an error message.

Characteristics of number extractor

The number extractor tool has the following characteristics:

  • The tool can recognize all integers, both negative and positive, as well as real numbers.
  • It cannot recognize fractions, so any number written in fraction form would result in two different numbers, the numerator and the denominator separately. Any fraction should be entered as a floating-point number to avoid any errors.
  • If there are no numbers in the text inputted, the output is null and the tool would display an error message.
  • The number extractor lists out all the numbers in the text irrespective of how many they may be, or how large the text is.
  • A text can be composed only of numbers. The tool recognizes each number as a separate entity.
  • Even if there is a repetition of numbers in the text, each instance of the number will be displayed separately.
  • The number extractor tool in use

    We now consider a few examples making use of the number extractor tool.

    Input:

    The integers are 1, 4, 9, 16, 25, 36, 49. The floating-point numbers are 3.1416, 53.78907 and 2.718. The negative numbers are -1, -2, -3, -4, -5, -6, -7.

    Output:

    1, 4, 9, 16, 25, 36, 49, 3.1416, 53.78907, 2.7818, -1, -2, -3, -4, -5, -6, -7


    Input:

    The value of pi is 3.1416, the value of Euler’s number (e) is 2.718 and the value of acceleration due to gravity on Earth is 9.8 m/s2.

    Output:

    3.1416, 2.718, 9.8


    Input:

    The recipe for brownies requires the following ingredients 1.5 cups powdered sugar, 0.75 cup flour, 2 large eggs, 0.5 cup dark chocolate chips and 0.5 teaspoon vanilla.

    Output:

    1.5, 0.75, 2, 0.5, 0.5


    Input:

    5 - 4 = 1, 5 + 4 = 9, 5 / 4 = 1.25, 5 × 4 = 20.

    Output:

    5, 4, 1, 5, 4, 9, 5, 4, 1.25, 5, 4, 20


    Input:

    The author of the book, Jurassic Park, is Michael Crichton.

    Output:

    No numbers found


    Areas of application

    The number extractor is useful in the following cases:

  • If the text to be analysed is really long, it can be quite difficult to take every single number into account. If one goes through the list manually, it is quite likely for them to miss out on one or two numbers in the list. One such example is a list of students in a class containing their names, register numbers and phone numbers. The tool would list out all the phone numbers along with the corresponding register numbers.
  • In computer programming, we often need to work only with the numbers in a line of text. In such cases, the number extractor tool is very useful.
  • The number extractor records every single number in the text, even if they are repeated. This is also quite useful for programming purposes.

  • See also: