AQA · GCSE · Computer Science

    Course version: 8525 · Version from Sept 2020

    String handling operations in a programming language: real to string.

    Converting a real (a number with a fractional part, such as 3.75) to a string means producing a text value that represents that number so it can be joined to other text, printed, or stored as…

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

    • Point 11 of 11

    Study notes

    From the checked teaching notes for this specification point.

    The idea

    Converting a real (a number with a fractional part, such as 3.75) to a string means producing a text value that represents that number so it can be joined to other text, printed, or stored as characters. In most languages you call a conversion function, for example str(3.75) in Python, which returns the string "3.75". The result is text, not a number: you cannot add it arithmetically, but you can concatenate it. Watch the decimal point and any trailing digits, and remember that the string keeps the digits the language chooses to display. A common use is building a message such as "Temperature: " + str(reading). The reverse operation, string to real, parses text back into a number.

    What earns the marks

    • Identifies that converting a real to a string produces a text value representing the number, e.g. str(3.75) giving "3.75".
    • Recognises the result is a string and so supports concatenation but not arithmetic.
    • Notes that the decimal point and fractional digits are retained in the string representation.
    • Distinguishes real-to-string conversion from string-to-real (parsing) conversion.

    Common mistakes and how to put them right

    • Thinking the converted value is still a number that can be added.

      Put it right by stressing the result is text and only concatenation applies.

    • Assuming the string always shows an exact fixed number of decimal places.

      Put it right by noting the language decides the displayed digits.

    • Confusing real-to-string with integer-to-string.

      Put it right by pointing out the fractional part and decimal point are kept.

    Exam tips

    • Read the code carefully to see whether a conversion function is applied before concatenation.
    • Check whether the question asks for the output as text or as a number before choosing an answer.
    • Trace the value step by step, noting the decimal point stays in the string.

    Try the lesson

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

    Have a go first

    A program stores the value 3.5 in a variable called price, which holds a real number. The programmer wants to join this value onto the end of a text message. Which operation converts the real number into text so it can be joined to a string?

    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: real to string.

    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