AQA · GCSE · Computer Science

    Course version: 8525 · Version from Sept 2020

    String handling operations in a programming language: string to real

    Converting a string to a real means taking text that holds a decimal number, such as the input "3.75", and turning it into a floating-point value the program can calculate with.

    Checked against the AQA 8525 specification (opens in a new tab) on .

    • Point 9 of 11

    Study notes

    From the checked teaching notes for this specification point.

    The idea

    Converting a string to a real means taking text that holds a decimal number, such as the input "3.75", and turning it into a floating-point value the program can calculate with. Input read from the keyboard usually arrives as a string, so arithmetic on it fails until conversion happens. The learner should recognise the operation, choose the correct target type (real, not integer, because a fractional part must survive), and predict the result. For example, converting "12.5" gives the real 12.5, which can then be multiplied. Converting "12.5" to an integer would lose the .5, so the target type matters. A value that is not numeric, such as "twelve", cannot be converted and would cause an error.

    What earns the marks

    • Identifies that string-to-real conversion changes a text value holding a decimal number into a floating-point (real) value.
    • Recognises that keyboard input is typically received as a string and must be converted before decimal arithmetic.
    • Selects real (floating-point) rather than integer as the target type when a fractional part must be preserved.
    • Predicts the resulting real value for a given numeric string, e.g. "3.75" becomes 3.75.
    • Recognises that a non-numeric string cannot be converted and would raise an error.

    Common mistakes and how to put them right

    • Choosing integer as the target type.

      Put it right: Is that a real preserves the fractional part, so "3.75" must become a real, not an integer.

    • Assuming input is already numeric.

      Put it right: Is that input is normally a string and needs explicit conversion before arithmetic.

    • Believing any text can be converted.

      Put it right: Is that only strings representing valid numbers convert; others cause an error.

    Exam tips

    • Read the question's target type carefully: real means decimal values are kept.
    • Check whether the string contains a decimal point to decide between real and integer.
    • Remember input is a string until converted, so state the conversion step explicitly.

    Try the lesson

    The start of the String handling operations in a programming language: string to real lesson, made from checked teaching notes for this specification point.

    Have a go first

    A program has the text "0.5" stored in a variable. Which type of value is produced when this string is converted to a real number?

    There is more to this lesson

    The full lesson goes on to check your understanding and help you earn the marks. Create a free account to carry on, with your progress saved.

    Carry on with the full lesson

    A week of Premium from your first lesson · Then the free plan continues · No card, no charge

    Test your understanding of String handling operations in a programming language: string to real

    Active recall beats re-reading. Take an instant quiz now to test what you’ve learned and lock it into long-term memory.

    Take topic quiz

    A week of Premium from your first lesson · Then the free plan continues · No card, no charge