STR$: Your Number-to-Text Transformer

STR$: Your Number-to-Text Transformer

Tired of numbers only speaking their numerical language? Want to give them a voice in the world of text? Look no further than the STR$ command, your number-to-text transformer! This handy function takes any numeric value and converts it into a string representation, allowing you to combine it with other text, display it in formatted ways, or manipulate it like any other string. It's like teaching your numbers how to speak in complete sentences!

Syntax

STR$(<number>)

Where: - <number>: The numeric value you want to convert into a string. This can be any valid numeric expression.

Applications

The STR$ function is your go-to tool when:

  • Displaying formatted numbers: Add leading zeros, currency symbols, or other text elements to your numeric output.
  • Concatenating numbers and text: Combine numbers with other text for messages, labels, or data output.
  • Creating custom input prompts: Generate dynamic prompts that include numeric values.
  • Manipulating numbers as text: Use string functions like LEFT$, RIGHT$, and MID$ to extract digits or manipulate the numeric string.

Code Examples

1. Simple Number Conversion:

10 X = 42
20 X$ = STR$(X)  :rem X$ now stores the string " 42" 
30 PRINT X$      :rem Output:  42

Notice the leading space when converting positive numbers to strings. This behavior is specific to Commodore 64 BASIC.

2. Formatting Output:

10 INPUT "Enter a score: "; S
20 PRINT "Score: "; STR$(S); "/" ; STR$(100) :rem Add "/" and "100" to the score

This code would output something like: Score: 85/ 100

3. Concatenation:

10 A = 10
20 B$ = " apples"
30 C$ = STR$(A) + B$  :rem C$ now stores " 10 apples"
40 PRINT C$           :rem Output:  10 apples

STR$ in the Wild: The Dynamic Label Maker

Imagine you're creating a program to display a bar graph on the Commodore 64. You could use STR$ to dynamically generate labels for the bars, showing the numerical value each bar represents alongside its graphical representation.

Don't let your numbers be confined to the realm of mathematics! With STR$, you can unleash their expressive potential, transforming them into words and phrases that can be combined, manipulated, and displayed in creative ways. It's like giving your numbers a new language to speak, opening up a world of possibilities for communication and interaction. So go ahead and give STR$ a try – let your numbers have their say!


Privacy Policy

Let's be honest, we collect some data. But we promise not to sell it, we'll mostly use it to improve our service. You can read the nitty-gritty details below, but be warned, it uses big words that lawyers like (we don't judge).

By using our service, you agree to this privacy policy. This disclaimer strikes a balance between lightheartedness and informing users that they should still read the full privacy policy if they choose.